Random generator exercise
ncouch
ncouch at mail.airmail.net
Wed Jan 22 13:11:01 EST 2003
I am in a bit of a quandry trying to tweak this script. It's main function
is to generate a random sequence of from 1-9 alpha and numerical characters.
The main problem I am having is updating the global value of x after each
run of the repeat loop.
As it stands right now it keeps resetting the value back to "1" after each
loop. I understand why it does this, but don't understand why I can't reset
the value after each run. Anyone have any ideas on how I might do this.
Here is the script so far:
=================================================
on MouseUp
-- setting things up
put empty into field "random"
put empty into field "rn"
put empty into field "valx"
ask "How many characters do you want? (# between 1 and 9)"
put it into field "valrn"
put it into valrn
put 1 into x
-- generating the random sequence
repeat until x=(valrn+1)
put random(2) into rc
put rc into line x of field "rn"
if rc=1 then
ralpha -- an alpha character
else rnum -- a number
add 1 to x
end repeat
end MouseUp
on ralpha
global x
put random(26) into rn
get char rn of field "alpha"
put it into char x of field "random"
end ralpha
on rnum
global x
put random(9) into rn
put rn into char x of field "random"
end rnum
=================================================
Cheers,
Nate
More information about the use-livecode
mailing list