Can i Make RANDOM more Random?
Tomjr
Posts: 2
Im currently working on what should have been a simple program that would generate a frequency through a small speaker on a bs2 stamp.· I've tried employing the Random function, but when i restart the program, it does the same tones again, they seem random, but they arent.· Also i have random plugged into the pause between the noise, and the length of the noise.
Is there a way to make a random seed? or use the time to calculate a random variable?
Please help
PS: Dont hit me with a bunch of terms, i probably wont know them.. i'll try and understand.
Thankyou
Edit, here's the program as i have it so far:
' {$STAMP BS2}
' {$PBASIC 2.5}
Spkr·········· ·· PIN···· 15
TmAdj········ · CON···· $100
FrAdj········· · CON···· $100
R··········· ···· VAR···· Word
R2············· · VAR···· Word
FREQ········ ·· VAR···· Word
PAWZ·········· VAR···· Word
R3············· · VAR···· Word
R4·············· ·VAR···· Word
PAWZ2········· VAR···· Word
Main:
R=R+1
RANDOM R
R2=R//10+2
FREQ=R2*1000
R3=R//6+1
PAWZ=R3*1000
R4=R//10+1
PAWZ2=R4*1000
FREQOUT Spkr, PAWZ2 */ TmAdj, 1 */ FrAdj, FREQ */ FrAdj
PAUSE PAWZ
GOTO Main:
Post Edited (Tomjr) : 5/16/2007 1:46:06 PM GMT
Is there a way to make a random seed? or use the time to calculate a random variable?
Please help
PS: Dont hit me with a bunch of terms, i probably wont know them.. i'll try and understand.
Thankyou
Edit, here's the program as i have it so far:
' {$STAMP BS2}
' {$PBASIC 2.5}
Spkr·········· ·· PIN···· 15
TmAdj········ · CON···· $100
FrAdj········· · CON···· $100
R··········· ···· VAR···· Word
R2············· · VAR···· Word
FREQ········ ·· VAR···· Word
PAWZ·········· VAR···· Word
R3············· · VAR···· Word
R4·············· ·VAR···· Word
PAWZ2········· VAR···· Word
Main:
R=R+1
RANDOM R
R2=R//10+2
FREQ=R2*1000
R3=R//6+1
PAWZ=R3*1000
R4=R//10+1
PAWZ2=R4*1000
FREQOUT Spkr, PAWZ2 */ TmAdj, 1 */ FrAdj, FREQ */ FrAdj
PAUSE PAWZ
GOTO Main:
Post Edited (Tomjr) : 5/16/2007 1:46:06 PM GMT
Comments
or add a real time clock and do the same thing with the seconds or what ever.
how about adding a photo resistor and using the RC time command to get a value as a random seed. this might not be different enough in a controlled environment. but just a thought.
as I understand it there is no real random generator with out a seed. it's just a list of numbers that were randomly selected at some point. another instructor said that the government won't allow real random number generators because encryption would be unbreakable. not sure I believe that one.
good luck.
1) You could attach an external real time clock and use the time to initialize "R".
2) You could add a "start" button and increment "R" during initialization until the button is pressed.
3) You could add an external timer using a 555 to put out a short pulse every second or half second, then, during initialization, wait for the pulse to appear. The time between the Stamp's reset and the 555 pulse could be used to initialize "R". You want to be careful not to reset the 555 (except when the power is turned on).
thanks for the ideas.
- Tommy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·[noparse][[/noparse]IMG]http://i155.photobucket.com/albums/s305/Tomjr-/userbar4.png[noparse][[/noparse]/IMG]
The only true random number generators are the ones that are based on some kind of random physical process. Usually it's radioactive decay. They have a speck of some radioactive material like Polonium (used in some smoke detectors) and count the number of alpha particles emitted in a period of time (like a Geiger counter) and use that.
Running a count is OK, but that still won't give you random numbers immediately upon startup. Using a Real Time Clock or any external sensor (such as the RCTIME on a photoresistor) will give you some kind of seed right away for random numbers, e.g.
Edit: as usual Mike G. beats us to the punch!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST