I think I found a better way [Random Number Gen]. Comments?

IronJungle

Senior Member
I did a code mod on my Etch a Sketch Temperature Data Logger to have the stylus just "move around randomly".

Since the PICAXE 18M2 random number generator is pseudo, the patterns were not very entertaining. In a word they were very predictable. If I had a timer chip, etc. I could just use the seconds or such to seed the RANDOM command from time to time. But I don't have that option. Here is my solution and I would like comments.

I can say for certain that the Etch a Sketch display drawn is now very unpredictable and a zillion time improvement. My code:

touch16 TouchRandomizer, b0 'lower bits w0
touch16 TouchRandomizer, b1 'w0 upper
RANDOM w0

I leave the touch pin on the 18M2 open/floating so it is moves all over the place when viewed in debug.

Comments?
 
Last edited:

mrburnette

Senior Member
Ummmm, now that pretty creative IronJungle. Wonder how that would work where the PICAXE circuit was in a metal box... do we get enough stray RF noise in the enclosure of does the enclosure act as a Faraday shield? Looks like an experiment some late evening will be in order.

Thanks for the tossing this one out into the wild... I could surely have used this last year.


Ray
 

g6ejd

Senior Member
Well, assuming the atmospheric noise is wide-band and largely random (usually the case) and your circuits' response is quite wide, then to me this looks like a really good solution, I guess you no-longer see any skewing in the results to confirm the improvement.
 

mrburnette

Senior Member
@g6ejd...
My thinking until I got to thinking about shielded designs. I guess I really am more interested in where the specific, main voltage component of the "noise" is originating so that I can understand the implications of how to use this effectively and not diminish the effect by doing something like using a metal enclosure instead of plastic! Like, I'm the dude that would always paint himself into a corner... :D
 

IronJungle

Senior Member
Here are two pics showing the difference beween the method mentioned in post #1 vs not seeding the RANDOM function with 'touch16'.

The programmed draw algorithm randomly decides to move the Etch a Sketch "up or down" 5 stepper steps. Then "left or right" 5 stepper steps. The plots are of 2,500 events. If "out of bounds" is reached the stylus re-centers.

Without the 'touch16' seed the plot is pretty lame (as expected when you understand the PICAXE RANDOM command.
2012-07-01 17.50.07.jpg2012-07-01 17.54.09.jpg
 

IronJungle

Senior Member
A bit of follow up. Pic is after 50,000 moves. You can tell that the "in bounds" area has been covered pretty well. I'm calling this method random enough. It wouldn't qualify for a random number generator in a casino, but it is plenty random enough for a hobby project.
2012-07-04 18.06.58.jpg
 

AllyCat

Senior Member
If "out of bounds" is reached the stylus re-centers.
Hi,

An ingenious and interesting idea. But wouldn't it be better to "bounce" the stylus off the "walls" (i.e. reverse the direction of movement) in the same way that Pong and some of the classic screensavers work?

Cheers, Alan.
 

IronJungle

Senior Member
Allan. Your idea is probably better. However, I wanted this experiement to double as a way to check my stepper motor step count routines with the "return to center" method.
 

HertzHog

Member
Randomiser code.

I did a code mod on my [URL="http://www.picaxeforum.co.uk/showthread.php?21556-quot-Etch-a-Sketch My code:

touch16 TouchRandomizer, b0 'lower bits w0
touch16 TouchRandomizer, b1 'w0 upper
RANDOM w0

Comments?
I thought touch16 needed a word variables or the result or am I missing something subtle or just being dim? HertzHog
 

IronJungle

Senior Member
I am the OP.

I was just using the touch feature to get a random number. My thought was the lower bits would be more noisey (random) than the upper bits.
w0 is comprised of b0 and b1.

So... I read the touch16 twice, then combine them into w0.
 
Top