Random number
Learning from scratch
Posts: 14
Hi out there, I'm trying to make a radom number generator with five outputs,· this is to blink lights in a radom matter, being new at this, would beg for some help.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Old redneck hillbilly born and raised on a redwood stump
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Old redneck hillbilly born and raised on a redwood stump
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Bill Horn
Crescent City
bill.horn@charter.net
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Old redneck hillbilly born and raised on a redwood stump
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
here is the old code, would like it for BS1.
port = &H378
RANDOMIZE TIMER
ct = 0
DO UNTIL ct = 5
FOR CR = 1 TO 31
r = INT(31 * RND + 1)
FOR I = 1 TO C * 2.5 'DELAY
NEXT I
LOCATE 6, 30: PRINT "TWENTY ONE "
LOCATE 8, 30: PRINT "RANDON ALL "
IF r = 1 THEN
OUT port, 1
ELSEIF r = 2 THEN
OUT port, 2
ELSEIF r = 3 THEN
OUT port, 3
ELSEIF r = 4 THEN
OUT port, 4
ELSEIF r = 5 THEN
OUT port, 5
ELSEIF r = 6 THEN
OUT port, 6
ELSEIF r = 7 THEN
OUT port, 7
ELSEIF r = 8 THEN
OUT port, 8
ELSEIF r = 9 THEN
OUT port, 9
ELSEIF r = 10 THEN
OUT port, 10
ELSEIF r = 11 THEN
OUT port, 11
ELSEIF r = 12 THEN
OUT port, 12
ELSEIF r = 13 THEN
OUT port, 13
ELSEIF r = 14 THEN
OUT port, 13
ELSEIF r = 15 THEN
OUT port, 15
ELSEIF r = 16 THEN
OUT port, 16
ELSEIF r = 17 THEN
OUT port, 17
ELSEIF r = 18 THEN
OUT port, 18
ELSEIF r = 19 THEN
OUT port, 19
ELSEIF r = 20 THEN
OUT port, 20
ELSEIF r = 21 THEN
OUT port, 21
ELSEIF r = 22 THEN
OUT port, 22
ELSEIF r = 23 THEN
OUT port, 23
ELSEIF r = 24 THEN
OUT port, 34
ELSEIF r = 25 THEN
OUT port, 25
ELSEIF r = 26 THEN
OUT port, 26
ELSEIF r = 27 THEN
OUT port, 27
ELSEIF r = 28 THEN
OUT port, 28
ELSEIF r = 29 THEN
OUT port, 29
ELSEIF r = 30 THEN
OUT port, 30
ELSEIF r = 31 THEN
OUT port, 31
END IF
NEXT CR
ct = ct + 1
LOOP
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Old redneck hillbilly born and raised on a redwood stump
For those wondering why RANDOM is tossed three times ... we found this gives a more visually-interesting display when used in this kind of program.· RANDOM uses an LFSR (linear feedback shift register) and the nature of that design causes us to "see" the shifting of bits through it when RANDOM is called just once.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Again tks so much
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Old redneck hillbilly born and raised on a redwood stump
· OUT port, r
... could have replaced all those IF-THEN constructs as you had already limited r to 1..31.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax