Shop OBEX P1 Docs P2 Docs Learn Events
to modify a random flicker — Parallax Forums

to modify a random flicker

nick bernardnick bernard Posts: 329
edited 2004-08-23 20:40 in General Discussion
i'm using vb to generate 3 random integers ranging from 0 to 255. i write these numbers to 3 cascaded shift registers via bs2sx. the registers drive led's to observe the bit patern, i have observed that the random seed generates a very tight on/off ratio and seldom goes beyond 14:18.

supposed i wanted to introduce another variable (rate)·into the function that could significantly reduce or increase that ratio.
the only solution i could come up with on the fly is to set each bit individually; however since i cannot reference bits in vb i'd have to introduce some shifty arithmatic such as


sub flicker(rate as integer) as byte
· for cx = 0 to 7
····· randomize
······if rnd * 255 > rate
······· seed = seed * 2 + 1
····· else
······· seed = seed * 2
····· end if
···next
···flicker = seed
end function

is there a simpler algorithm that does not involve iteration?
thx nick

·
Sign In or Register to comment.