Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Looking for a SCRAMBLE() Function
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00565279
Message ID:
00565358
Vues:
17
This message has been marked as a message which has helped to the initial question of the thread.
Hi!

Following is the most simple method (algorithm complexity proportional to number of characters in the string, if stuff() for 1 character works quickly):
lparameters lcStr ' you can pass it also by reference
local lnLen, lnPos1, lnPos2
m.lnLen = len(m.lcStr)
for i=1 to m.lnLen+m.lnLen+m.lnLen
  m.lnPos1 = ceiling(rand()*m.lnLen)
  m.lnPos2 = ceiling(rand()*m.lnLen)
  if m.lnPos2 # m.lnPos1
    m.lcStr = stuff(stuff(m.lcStr,m.lnPos2,1,substr(m.lnPos1,m.lcStr,1)), ;
      m.lnPos1,1,substr(m.lnPos2,m.lcStr,1)) + 
  endif
endfor
return m.lcStr
>I was hoping to find a pre-existing function in VFP that would have functionality along the lines of:
>
>SCRAMBLE("word") which would return any of the following:
>
>ordw rodw rowd drow ordw owdr
>
>and so on. Basically, I want to randomly scramble the letters within a word.
>
>Any suggestions?
>
>TIA
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform