Step 3Generating Random Numbers
It turns out that creating true randomness is very difficult. It may even be impossible. Using mathematics and computer programs to create random number generators creates a sequence of numbers that are not truly random. Because they are mathematical and from a known formula--they are predictable. They are thus call pseudo-random number generators (PRNGs). It also turns out that so far no one has been able to create a random number algorithm that does not repeat itself. It does not matter how big the program or formula, the pattern eventually begins to repeat itself. No matter how hard we intentionally try to create randomness, there is an underlying tendency towards order that asserts itself.
True random number generators (TRNGs), use electronic or environmental noise to generate the number and on the surface appear to be more random than pseudo random generators. However if we knew enough about the mechanics of the generation of such noise, we would most likely be able to predict the numbers generated. Just because we are not smart enough or perceptive enough to predict something does not make it inherently unpredictable. Such generators are also notoriously sensitive to their environment and will often pick up repetitious patterns from the environment around them (AC hum, florescent frequencies, temperature variations, etc.).
A Pseudo Random Number Program
In the program below you can see how I used the Picaxe microcontroller to generate pseudo random numbers to play frequencies over a two octave range. Depending on the number (b8) a note is picked and played for a short time (b6) and then one of seven colors is picked to light up for a short period of time. Then the process repeats itself.
TEXT OF PROGRAM:
'Random music and light generator
symbol time =b3
loop:
high 0
high 1
high 4
'readadc 1,b12
'debug b12
random w0
random w1
time=1
b9=b1+b3
b8=b9/7
pause 57
'$0C pause ,$1A,$1B
lookup b8,($20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$2A,$2B,$00,$01,$02,$03,$04,$05,$06,$07,$08,
$09,$0A,$0B,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,
$1A),b6
tune 0, time,(b6)
pause 31
lookup b8,($25,$26,$27,$28,$29,$2A,$2B,$00,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0A,$0B,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$1A),b6
tune 0, time,(b6)
pause 21
lookup b8,($28,$29,$2A,$2B,$00,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0A,$0B,$10,$11,$12,$13,$14,$15,$16,$17),b6
tune 0, time,(b6)
pause 11
branch b8,(p6,p3,p1,p2,p6,p3,p2,p5,p4,p5,p7,p1,p8,p2,p1,p2,p6,p3,p2,p5,p4,p5,p7,p1)
goto loop
p1: 'random pauses
low 0 'white
low 1
low 4
pause 41
goto loop
p2:
low 1 'green
pause 61
goto loop
p3:
low 4
pause 65 'blue
goto loop
p4:
low 0 'yellow
low 1
pause 53
goto loop
p5:
low 1 'blue green
low 4
pause 31
goto loop
p6:
low 0 'violet
low 4
pause 57
p7:
low 0 'red
pause 67
p8:
goto loop
| « Previous Step | Download PDFView All Steps | Next Step » |









































a Mac (hence MacAXEpad ) User
and
just tried to look at the code
receiving the message "error: loop without Do" message -
this happens with a lot of other PIcaxe script
which i downloaded too,
hence it must be me
who "does smthng wrong" -
may you please provide a hint
on this (for an absolute newbee)?
i look forward to your reply!
If you change loop: to loop1:
and change all instances of goto loop to goto loop1 that should solve the problem.
This program worked fine with the older picaxe programming software until the word "loop" became part of the command set in the newer programming software. So loop can no longer be used as a label unless you add additional numbers or letters to it.
but now the code gets stuck at ....
lookup b8,($20,$2 ....
.... telling me about syntax errors.
am a bit worried that eventhough i work myself through
whole script it's functionality might suffer from my corrections.
however and whatever remains:
such a shame they changed the syntax -
i like your project !
i need to teach myself/learn about the alterations
of the current script - and "translate" it.
thanks for you rreply
& have a great day!