3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Build a Random Music and Light Generator and Glimpse Evidence of GOD

Step 3Generating Random Numbers

Generating 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 StepDownload PDFView All StepsNext Step »
2 comments
Jul 17, 2011. 2:31 PMmarc_is_curious says:
Am totally new to Picaxe
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!
Jul 18, 2011. 12:33 PMmarc_is_curious says:
good hint - thanks -
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!

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
387
Followers
26
Author:mikey77
I believe that the purpose of life is to learn how to do our best and not give in to the weaker way.