[Robotgroup] Basic Stamp RANDOM
Vern Graner
vern at txis.com
Wed May 21 16:43:07 PDT 2008
Kevin Booth wrote:
> Is there anyway to get around the non-randomness of the RANDOM statement?
> Currently every time i use it i get the same result.
>
> Please help =D
Everything you need to know by Jon Williams of Parallax/ Nuts & Volts/
EFX-TEK fame:
http://www.efx-tek.com/php/smf/index.php?topic=41.0
Excerpt from the above:
------------------- CLIP --------------------
One of the most compelling reasons to use a programmable controller like
the Prop-1, Prop-2, or Prop-SX in your designs is a function of the
respective languages called RANDOM. To be fair, RANDOM isn't truly
random, it is in fact pseudo-random. What this means is that the
algorithm used generates a seemingly random list of values each time
it's called. The result of the RANDOM function is wholly dependent on
the seed value feed to it; same seed, same result.
That said, our props are often waiting for something to happen, perhaps
a PIR or mat switch to detect a guest. While waiting, we can
continuously call RANDOM and thus end up with a truly random value;
we're using random timing of the external event to drive the value.
Here's what it looks like in code:
Main:
RANDOM lottery
IF PIR = No THEN Main
As you can see, the RANDOM function will be called until the PIR goes
active, and that is a random event, hence we end up with a random value
in lottery.
Just a note: When using RANDOM to drive LEDs to create a candle-flicker
effect, you should stir the random value a few times before sending it
to the LEDs. The reason is that the algorithm used for RANDOM is called
a Linear Feedback Shift Register, and while the decimal values look
random, one can see the apparent linear motion of the bits when the
output is connected to parallel LEDs. The fix is easy:
Light_Candles:
FOR idx = 1 TO 3
RANDOM lottery
NEXT
Wicks = lottery
PAUSE 25
GOTO Light_Candles
------------------- /CLIP -------------------
There's a lot more discussion in the thread. :)
Vern
--
Vern Graner CNE/CNA/SSE | "If the network is down, then you're
Senior Systems Engineer | obviously incompetent so why are we
Texas Information Services | paying you? Of course, if the network
http://www.txis.com | is up, then we obviously don't need
Austin Office 512 328-8947 | you, so why are we paying you?" İVLG
More information about the Robotgroup
mailing list