Can someone explain what "random" does?
lardom
Posts: 1,659
There is an operator called Random Number Forward "?X" and Reverse "X?" which generate integers that are a puzzle to me. I modified an object I found in the OBEX to display those random numbers on the PST. I've attached a screenshot of the PST display and the modified object itself. The random numbers are being used to control pulse width which works but which makes no sense to me.:nerd:
Comments
In the BASIC Stamp RANDOM only goes forward, in the Propller, ? can go either direction. Here's a simple Propeller demo that demonstates that ? is math-based, not truly random:
If you look at the screen-shot of the output you'll see that the starting seed (1234) is returned to after running ? backward the same number of times we went forward.
A lot of my coding for props (movie and Halloween props, that is) and what I tend to do is use some external event to drive the randomness. For example, I might do something like this in a Halloween prop:
This code will stir the random number (seed) until a valid trigger event, then create a delay from that. By using an external event the number becomes truly random. You can't always do this, and there is an object written by Chip Gracey that gives very random numbers without an external event; that said, it does require an extra cog.
But in recently reading about electronic noise in op amps, I found the comment that thermal noise in a resistor is random (truely random Brownian motion). So why can't one merely amplify the noise, sample its level as required as a byte or word or whatever, and use that as your random number?
http://en.wikipedia.org/wiki/Monte_Carlo_method
Massimo
I always liked the two transistor avalanche noise generator as shown nicely here: http://www.cryogenius.com/hardware/rng/
It appeals to me because of the odd way the transistors are wired up.
Don't forget to apply the Von Neumann method in software to un-bias the results (ensure there are equal numbers of zeros and ones).
Haven't made one for the Prop yet but often thought I want to.
Never mind about interference from outside and superiority quantum noise sources. I'm sure for 99% of normal uses this is as good as it gets. Run it from batteries in a lead box with optical coupled output. The noise from all the consciousness' around will upset it anyway:)
if you base the SEED on a free running counter that stops when a user presses a button (and maybe also release) should be considered good enough.
Phil created a randomizer based on PLL jitter.
Running four of the props counter at different speeds, you should be able to create something below.
Quote:
All VIA C3 microprocessors have included a hardware RNG on the processor chip since 2003.
Instead of using thermal noise, raw bits are generated by using four freerunning oscillators which
are designed to run at different rates.
The output of two are XORed to control the bias on a third oscillator, whose output clocks the output
of the fourth oscillator to produce the raw bit. Minor variations in temperature, silicon characteristics,
and local electrical conditions cause continuing oscillator speed variations and thus produce the entropy of the raw bits.
http://www.via.com.tw/en/downloads/whitepapers/initiatives/padlock/evaluation_summary_padlock_rng.pdf