Random generator exercise

dan johnson danjohnson at 37.com
Thu Feb 6 09:15:01 EST 2003


miscdas writes:

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
########

MISCDAS,

That is an unusual non-intuitive solution to the problem. Was this a spin-off of the solution you gave using the text string? Did you happen to run any timing to see how slow the IF-THEN_ELSE conditionals are compared to the "intuitive" solution?

I've been reviewing the archives, and noticed you presented some other non-intuitive solutions to other problems. I hope you will be able to continue to present these kinds of thought-provoking methods.

Regards,

Dan J.

------------------------------------------------------------
http://Game.37.com/  <--- Free Games
http://newJoke.com/   <---  J O K E S  ! ! !



More information about the use-livecode mailing list