Random generator exercise

miscdas at boxfrog.com miscdas at boxfrog.com
Tue Feb 4 11:32:01 EST 2003


Here is yet another approach to the exercise. 

A SINGLE random number is generated, from which a numeric or an alpha 
character is generated. 

There is a .5 probability of generating a numeric, and .5 probablity of 
generating an alpha. 

Within the alpha, there is a .5 probablity of being lower case, and .5 
probablity of being upper case. 

on mouseUp
put empty into field “displayField”
ask ("How many characters to generate ? (1-9)")
put it into charCount
  repeat charCount times
   put random(520) into myRandom
   if myRandom < 261 then  ##numeric
     put (myRandom - 1) div 26  after field “displayField”
   else
     if myRandom < 391 then
       put 45 into offsetASCII  ##lowercase
     else
       put -13 into offsetASCII  ##uppercase
     end if
    put (myRandom – 1) div 5 + offsetASCII into finalValue
    put numToChar(finalValue) after field “displayField”
   end if
 end repeat
end mouseUp 


miscdas



More information about the use-livecode mailing list