Shop OBEX P1 Docs P2 Docs Learn Events
Generating seed value for random number generator — Parallax Forums

Generating seed value for random number generator

NateNate Posts: 154
edited 2006-02-18 00:51 in General Discussion
I'm using a SX28, and need to generate a seed value (~1-9) for a random number generator - should be the lowest part count possible (need I mention this?).· I was thinking about using some sort antenna, and sampling the voltage level of the signal when the SX needed the seed value.· Maybe I'm getting too complicated - anyone made anything simple to produce a random number seed?

Nate

Comments

  • Mike CookMike Cook Posts: 829
    edited 2006-02-17 22:03

    Well if you want a hardware solution, you could pick up one of the RLP-434 receivers from www.sparkfun.com They are just under $12.00 a set (transmitter/receiver), but I believe you can just purchase the receiver for around $6.00

    With out any kind of preamble or header detection, these things output all sorts of random junk when the transmitter is not transmitting. Use serin to grab a byte at 1200 or 2400 baud. I'll bet you'll never get the same byte twice in 50 or so samples.

    Mike

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "OEM NMEA GPS Module" Now available on ebay for only $17.49

    Product web site: http://www.allsurplus.net/Axiom/
  • John R.John R. Posts: 1,376
    edited 2006-02-17 22:32
    Does your system have a real time clock? Is there a counter that will vary with each "run" of your code? What other I/O do you have connected that you could "query" for a seed?

    If you have a clock, just take the "seconds" or factional seconds at the time you need the seed. The same could be done with a counter or input if they would be sufficiently "random" to be a good seed, or a good multiplier / divisor for some math to a "fixed" seed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.

    8 + 8 = 10
  • NateNate Posts: 154
    edited 2006-02-17 23:44
    The problem is that the code will be running the same number of instructions between each call to the random number generator so I cannot use the system clock.· There are no 'human' inputs (button presses) or other·I/O events·to grab the system clock signal and key off.· This is why I am looking for something external to the SX that will generate the seed - ideas discarded so far; ambient noise and light levels - may not be measurably random enough (need new seed about every 5 seconds).

    I like the·reciever idea, though I'm thinking simpler, such as a wire antenna and op-amp.

    Nate
  • Mike CookMike Cook Posts: 829
    edited 2006-02-18 00:25
    Well, how about a crystal radio, will pick up a bunch of AM stuff, could be as simple as a chunk of wire and a 1N34 diode.

    attachment.php?attachmentid=40510

    Mike


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "OEM NMEA GPS Module" Now available on ebay for only $17.49

    Product web site: http://www.allsurplus.net/Axiom/

    Post Edited (Mike Cook) : 2/18/2006 12:32:04 AM GMT
    114 x 200 - 4K
  • John R.John R. Posts: 1,376
    edited 2006-02-18 00:51
    Nate said...
    The problem is that the code will be running the same number of instructions between each call to the random number generator so I cannot use the system clock. There are no 'human' inputs (button presses) or other I/O events to grab the system clock signal and key off. This is why I am looking for something external to the SX that will generate the seed - ideas discarded so far; ambient noise and light levels - may not be measurably random enough (need new seed about every 5 seconds).


    I like the reciever idea, though I'm thinking simpler, such as a wire antenna and op-amp.



    Nate

    Do you really want/need a new "seed" every 5 seconds, or just at each start up. Once you give the first seed, the sequence of "what comes next" will vary with each different seed. "Normally" you just want a different seed each time the system sees a "cold start".

    If this is what you're after, how about just adding a real time clock (not the system clock) and then use the seconds and/or fractions? This would seem easier than the antenna concept.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.

    8 + 8 = 10
Sign In or Register to comment.