getting true randomness
Archiver
Posts: 46,084
Hi,
You don't say how many you need. If you don't need too many or
they can be reused how about storing in memory a sequence of
pre-generated random numbers and referencing them as needed?
Ken
"Place your hand on a hot stove for a minute, and it seems like
an hour. Sit with a pretty girl for an hour, and it seems like
a minute.
That's relativity." - Albert Einstein
---- On Fri, 26 Apr 2002, Ned Schwartz
(neddothekiddo@h...) wrote:
> Hi there, I am new here...
>
> I need a way to generate truly random word values for a
project I am working
> on. I was wondering if anyone could suggest something. I
tried using the
> open pins on my stamp as suggested in the PBASIC index, but I
just get a
> bunch of zeros. Is there anything I could hook up to these
pins that would
> cause them to generate randomness? Or does anyone have a
better method?
>
> thanks,
>
> Ned Schwartz,
> HitMaker
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the
Subject and Body of the message will be
> ignored.
>
>
> Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
>
>
>
>
You don't say how many you need. If you don't need too many or
they can be reused how about storing in memory a sequence of
pre-generated random numbers and referencing them as needed?
Ken
"Place your hand on a hot stove for a minute, and it seems like
an hour. Sit with a pretty girl for an hour, and it seems like
a minute.
That's relativity." - Albert Einstein
---- On Fri, 26 Apr 2002, Ned Schwartz
(neddothekiddo@h...) wrote:
> Hi there, I am new here...
>
> I need a way to generate truly random word values for a
project I am working
> on. I was wondering if anyone could suggest something. I
tried using the
> open pins on my stamp as suggested in the PBASIC index, but I
just get a
> bunch of zeros. Is there anything I could hook up to these
pins that would
> cause them to generate randomness? Or does anyone have a
better method?
>
> thanks,
>
> Ned Schwartz,
> HitMaker
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the
Subject and Body of the message will be
> ignored.
>
>
> Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
>
>
>
>
Comments
I need a way to generate truly random word values for a project I am working
on. I was wondering if anyone could suggest something. I tried using the
open pins on my stamp as suggested in the PBASIC index, but I just get a
bunch of zeros. Is there anything I could hook up to these pins that would
cause them to generate randomness? Or does anyone have a better method?
thanks,
Ned Schwartz,
HitMaker
>
>Hi there, I am new here...
>
>I need a way to generate truly random word values for a project I am
working
>on. I was wondering if anyone could suggest something. I tried using
the
>open pins on my stamp as suggested in the PBASIC index, but I just
get a
>bunch of zeros. Is there anything I could hook up to these pins that
would
>cause them to generate randomness? Or does anyone have a better
method?
>
>thanks,
>
>Ned Schwartz,
>HitMaker
>
Getting past the philosophical/mathematical implications of what
actually constitutes a TRUE random number [noparse]:)[/noparse].......Are you using the
RANDOM command? If you want more randomness than that offers alone,
you can use some sort of external(to the Stamp) trigger/sensor, and
use the output from that sensor to further randomize the RANDOM
command. Something as simple as a timed switch will work, or perhaps
use a light dependent resistor or something.
Paul Lugger
__________________________________________________________________
Get your free Australian email account at http://www.start.com.au
>
>I am using the RANDOM command, but I find that it falls into a
repetitive
>sequence after about 10-20 generated numbers. this is a big problem
as my
>program needs to be constantly generating random numbers.
>
>As far as the external thing goes, I thought that some sort of sensor
would
>work, but a) it needs to be fluctuating fairly often as I am
generating a
>new random number every quarter second or so and b) I think I need to
>generate a WORD sized number and, using one pin that would mean
sampling the
>input 65535 times to get a WORD value to start with. This is just too
much
>time.
>
>I suppose I could attach sensors to eight pins and add an inH from
one
>sample to the inH of the next... but, as far as light dependent
transistors
>or timed switches go, what do you have in mind?
>
>Ned
>
>> Getting past the philosophical/mathematical implications of what
>> actually constitutes a TRUE random number [noparse]:)[/noparse].......Are you using
the
>> RANDOM command? If you want more randomness than that offers alone,
>> you can use some sort of external(to the Stamp) trigger/sensor, and
>> use the output from that sensor to further randomize the RANDOM
>> command. Something as simple as a timed switch will work, or
perhaps
>> use a light dependent resistor or something.
>>
>> Paul Lugger
>>
RCTIME can be used to sample a word value in as little as 2 uS. The
problem is to find some sort of input/sensor which consistantly
outputs resistance or capacitive changes over a wide range of values,
and yet will change its output constanstly within a quarter second
cycle. Perhaps a radio signal tuned to white noise or a music
station? A crystal set perhaps? I'm not very experienced with
electronics, so I may be wrong, but thats one idea.
Paul Lugger
__________________________________________________________________
Get your free Australian email account at http://www.start.com.au
26 numbers, I still need a way of doing so randomly.
What I need to do is display characters on an LED display randomly, so that
is a to z plus a _space_ sequence. the letters need to be called up
completely randomly, as I am trying to make a display that could
"potentially" randomly generate words - the old infinite monkey on infinite
typewriters idea.
Ned Schwartz,
HitMaker
Original Message
From: "Ken Ambrose" <kenzo@u...>
To: "Ned Schwartz" <basicstamps@yahoogroups.com>
Sent: Friday, April 26, 2002 9:50 PM
Subject: Re: [noparse][[/noparse]basicstamps] getting true randomness
> Hi,
> You don't say how many you need. If you don't need too many or
> they can be reused how about storing in memory a sequence of
> pre-generated random numbers and referencing them as needed?
>
> Ken
>
>
> "Place your hand on a hot stove for a minute, and it seems like
> an hour. Sit with a pretty girl for an hour, and it seems like
> a minute.
> That's relativity." - Albert Einstein
>
>
>
>
> ---- On Fri, 26 Apr 2002, Ned Schwartz
> (neddothekiddo@h...) wrote:
>
> > Hi there, I am new here...
> >
> > I need a way to generate truly random word values for a
> project I am working
> > on. I was wondering if anyone could suggest something. I
> tried using the
> > open pins on my stamp as suggested in the PBASIC index, but I
> just get a
> > bunch of zeros. Is there anything I could hook up to these
> pins that would
> > cause them to generate randomness? Or does anyone have a
> better method?
> >
> > thanks,
> >
> > Ned Schwartz,
> > HitMaker
> >
> >
> > To UNSUBSCRIBE, just send mail to:
> > basicstamps-unsubscribe@yahoogroups.com
> > from the same email address that you subscribed. Text in the
> Subject and Body of the message will be
> > ignored.
> >
> >
> > Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
> >
> >
> >
> >
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>
sequence after about 10-20 generated numbers. this is a big problem as my
program needs to be constantly generating random numbers.
As far as the external thing goes, I thought that some sort of sensor would
work, but a) it needs to be fluctuating fairly often as I am generating a
new random number every quarter second or so and b) I think I need to
generate a WORD sized number and, using one pin that would mean sampling the
input 65535 times to get a WORD value to start with. This is just too much
time.
I suppose I could attach sensors to eight pins and add an inH from one
sample to the inH of the next... but, as far as light dependent transistors
or timed switches go, what do you have in mind?
Ned
> Getting past the philosophical/mathematical implications of what
> actually constitutes a TRUE random number [noparse]:)[/noparse].......Are you using the
> RANDOM command? If you want more randomness than that offers alone,
> you can use some sort of external(to the Stamp) trigger/sensor, and
> use the output from that sensor to further randomize the RANDOM
> command. Something as simple as a timed switch will work, or perhaps
> use a light dependent resistor or something.
>
> Paul Lugger
>
>
>
> __________________________________________________________________
> Get your free Australian email account at http://www.start.com.au
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>
>
>Original message from: "Ned Schwartz" <neddothekiddo@h...>
>>
>>I am using the RANDOM command, but I find that it falls into a
>repetitive
>>sequence after about 10-20 generated numbers. this is a big problem
>as my
>>program needs to be constantly generating random numbers.
>>
>>As far as the external thing goes, I thought that some sort of
sensor
>would
>>work, but a) it needs to be fluctuating fairly often as I am
>generating a
>>new random number every quarter second or so and b) I think I need
to
>>generate a WORD sized number and, using one pin that would mean
>sampling the
>>input 65535 times to get a WORD value to start with. This is just
too
>much
>>time.
>>
>>I suppose I could attach sensors to eight pins and add an inH from
>one
>>sample to the inH of the next... but, as far as light dependent
>transistors
>>or timed switches go, what do you have in mind?
>>
>>Ned
>>
>>> Getting past the philosophical/mathematical implications of what
>>> actually constitutes a TRUE random number [noparse]:)[/noparse].......Are you using
>the
>>> RANDOM command? If you want more randomness than that offers
alone,
>>> you can use some sort of external(to the Stamp) trigger/sensor,
and
>>> use the output from that sensor to further randomize the RANDOM
>>> command. Something as simple as a timed switch will work, or
>perhaps
>>> use a light dependent resistor or something.
>>>
>>> Paul Lugger
>>>
>
>RCTIME can be used to sample a word value in as little as 2 uS. The
>problem is to find some sort of input/sensor which consistantly
>outputs resistance or capacitive changes over a wide range of values,
>and yet will change its output constanstly within a quarter second
>cycle. Perhaps a radio signal tuned to white noise or a music
>station? A crystal set perhaps? I'm not very experienced with
>electronics, so I may be wrong, but thats one idea.
>
>Paul Lugger
>
The RCTIME statement will actually take 0.131 seconds to sample a full
WORD. But if all you need is a random number between 1 and 26, you
probably only need a byte. I think some sort of radiowave input/sensor
would be good because a properly tuned radiowave sensor is one of the
few sensors that will fluctuate nearly everywhere and all the time in
a seemingly random way.
Paul Lugger
__________________________________________________________________
Get your free Australian email account at http://www.start.com.au
>sequence after about 10-20 generated numbers. this is a big problem as my
>program needs to be constantly generating random numbers.
The sequence from the RANDOM command does repeat, but with cycle
length of 65536. It should give you way more than 10-20 numbers. Be
sure you use a WORD variable. Every time you start it at zero, it
gives the same sequence, so you will have to start ("seed the
sequence") at different points each time, or just let the sequence
continue without reseeding. Maybe you already did that and it is
still not random enough? I'll look back in my files. I think I
have another algorithm with a longer cycle length. These things are
tricky. Attempts to make a sequence "more random" with math tricks
sometimes backfire and have the opposite result.
>As far as the external thing goes, I thought that some sort of sensor would
>work, but a) it needs to be fluctuating fairly often as I am generating a
>new random number every quarter second or so and b) I think I need to
>generate a WORD sized number and, using one pin that would mean sampling the
>input 65535 times to get a WORD value to start with. This is just too much
>time.
As Paul said, the RCtime command can be used to capture a value. The
command is only good for about 10 bits of accuracy, and as you try to
measure longer time intervals, the last few bits are pretty much
noise.
1 meg
Vdd ---/\/\----o
P0
|
===== 0.33uF
|
Vss
x var word
loop:
RCtime 0,0,x
low 0
debug ?x
goto loop
With the values shown, this will show counts around 50000, but lots
of wiggle in the low digits. You will not get a full random word out
of this, but you could comine the least significant bits to the
number that you get from the RANDOM function.
There are things you can do to maximize the noise. For example, use
a long piece of wire to connect the bottom of the capacitor to Vss,
and connect it to a point in your circuit where lots of noisy digital
current will be expected. Loop the piece of wire up into the air or
around lots of digital circuitry or near a power line transformer.
Use a cheap capacitor (one with a high K, Y5U dielectric), to
maximize the soakage and temperature coefficient. And you could top
it off with a small thermistor or something like that as part of the
resistance, or a piece of piezo film (vibration sensitive) as part of
the capacitor.
more info on noisy RCtime...
<http://www.emesystems.com/BS2rct.htm>
-- regards,
Tracy Allen
electronically monitored ecosystems
mailto:tracy@e...
http://www.emesystems.com
be programmed to produce a series of random numbers that repeats only
after 2^N-1 numbers. It works by XORing certain bits and feeding back
the results to a software shift register. The entire generator is a
byte, word, or multiple words, for greater length, so this is an
efficient program for a Stamp. I've used this approach on many machines
to generate psuedorandom noise. For a really long sequence, 3 32-bit
sequences can be used together to produce a nonrepeating sequence that
repeats after 2^94 numbers. That's a long sequence. The universe is
only 2^49 seconds old.
Dennis
Original Message
From: Ned Schwartz [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=AXDwx62td6APsbidh8d6Hm9L5aP3lBwHAnbTQDNMa1n-YvYYcrsLctsPI-gNkXWiKY66Cq20k_pbtXDIRB1NRYdccA]neddothekiddo@h...[/url
Sent: Friday, April 26, 2002 10:14 PM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] getting true randomness
Hi there, I am new here...
I need a way to generate truly random word values for a project I am
working on. I was wondering if anyone could suggest something. I tried
using the open pins on my stamp as suggested in the PBASIC index, but I
just get a bunch of zeros. Is there anything I could hook up to these
pins that would cause them to generate randomness? Or does anyone have a
better method?
thanks,
Ned Schwartz,
HitMaker
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject
and Body of the message will be ignored.
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
I figured out what my problem was though. And it is pretty simple and
stupid. I was operating on the randomized result to get a value between 0
and 130 in 5 degree increments: 5(RANDOMresult/2520)=RESULT where random is
a WORD and RESULT is the variable after being operated on. my problem was
that I was using the operated on value (RESULT) to generate the next random
number:
result var word
loop:
RANDOM result
result = result / 2520
result = result * 5
goto loop
by simply adding another variable (STRIP) and letting that equal RESULT
before operating on it, I avoid the whole problem:
result var word
strip var word
loop:
RANDOM result
strip = result
strip = strip / 2520
strip = strip * 5
goto loop
This little alteration seems to keep the loop from falling into the
repetitive cycle that I was seeing by keeping the randomized number intact
after the math.
Thanks for the help though, I think that reading through the responses
helped me out in getting a better picture of what I was doing.
Ned Schwartz,
HitMaker
Original Message
From: "Tracy Allen" <tracy@e...>
To: <basicstamps@yahoogroups.com>
Sent: Saturday, April 27, 2002 10:46 AM
Subject: Re: [noparse][[/noparse]basicstamps] getting true randomness
> >I am using the RANDOM command, but I find that it falls into a repetitive
> >sequence after about 10-20 generated numbers. this is a big problem as my
> >program needs to be constantly generating random numbers.
>
> The sequence from the RANDOM command does repeat, but with cycle
> length of 65536. It should give you way more than 10-20 numbers. Be
> sure you use a WORD variable. Every time you start it at zero, it
> gives the same sequence, so you will have to start ("seed the
> sequence") at different points each time, or just let the sequence
> continue without reseeding. Maybe you already did that and it is
> still not random enough? I'll look back in my files. I think I
> have another algorithm with a longer cycle length. These things are
> tricky. Attempts to make a sequence "more random" with math tricks
> sometimes backfire and have the opposite result.
>
> >As far as the external thing goes, I thought that some sort of sensor
would
> >work, but a) it needs to be fluctuating fairly often as I am generating a
> >new random number every quarter second or so and b) I think I need to
> >generate a WORD sized number and, using one pin that would mean sampling
the
> >input 65535 times to get a WORD value to start with. This is just too
much
> >time.
>
>
> As Paul said, the RCtime command can be used to capture a value. The
> command is only good for about 10 bits of accuracy, and as you try to
> measure longer time intervals, the last few bits are pretty much
> noise.
>
> 1 meg
> Vdd ---/\/\----o
P0
> |
> ===== 0.33uF
> |
> Vss
>
>
> x var word
> loop:
> RCtime 0,0,x
> low 0
> debug ?x
> goto loop
>
> With the values shown, this will show counts around 50000, but lots
> of wiggle in the low digits. You will not get a full random word out
> of this, but you could comine the least significant bits to the
> number that you get from the RANDOM function.
>
> There are things you can do to maximize the noise. For example, use
> a long piece of wire to connect the bottom of the capacitor to Vss,
> and connect it to a point in your circuit where lots of noisy digital
> current will be expected. Loop the piece of wire up into the air or
> around lots of digital circuitry or near a power line transformer.
> Use a cheap capacitor (one with a high K, Y5U dielectric), to
> maximize the soakage and temperature coefficient. And you could top
> it off with a small thermistor or something like that as part of the
> resistance, or a piece of piezo film (vibration sensitive) as part of
> the capacitor.
>
> more info on noisy RCtime...
> <http://www.emesystems.com/BS2rct.htm>
>
> -- regards,
> Tracy Allen
> electronically monitored ecosystems
> mailto:tracy@e...
> http://www.emesystems.com
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>