loading

Can any one help me make a random # genorator?

Can anyone help me with an idea.. I want to make an Arduino Duemilanove random number genorator that will show up on 2 7-segments when I press a button. Any code suggestions, or help will be nice and if I ever make a instructable of it I will thank you all. Thanks!? I want help with a random # generator that will appear on 2 LED 7-segments, and will activate on the push of a button.

sort by: active | newest | oldest
mikeasaurus7 years ago
I'm certain there is someone here that will answer your question as it pertains to Arduino, however if you are looking for an alternative low-tech option Microsoft Excel can create random numbers quite easily with the RAND FUNCTION.

This can be expressed:
=INT(RAND()*(b-a)+a)
where b is the larger and a is the smaller

If you wanted a random 7 digit number your formula would look like:
=INT(RAND()*(9999999-999999)+999999)

To make 2 sets of numbers simply copy the formula over to another cell. To compute a new number just hit the cell again and a new number will be generated.
Just throwing this out as an alternative, or possibly something to hold you over until you finish sorting out an Arduino.
Hope this helps!

http://www.fourmilab.ch/hotbits/

Use this instead. Microsoft pseudorandom number generators make me sad.
legionlabs7 years ago
Here is a schematic for a fully functional quantum true random number generator:

http://www.defcon.org/images/defcon-17/dc-17-presentations/defcon-17-sean_boyce-quantum_random.pdf

I can confirm it works. Hope you're comfortable handling radioactives.

I wrote the code in assembly for AVR, should be easy to convert to arduino using the flowchart in the presentation. Bother me if you need source.

I've already done the most ridiculous parts of the statistical work, but you should test 25 megabits of output or so just to make sure it's running right using this tool:

http://csrc.nist.gov/groups/ST/toolkit/rng/index.html
AndyGadget7 years ago
A simple hardware implementation of a PRNG (pseudo random number generator) is a serial in-parallel out shift register with the input coming from various exclusive OR (XOR) elements along the length of the register. Only some configurations will produce the full possible sequence though.
I'm not familiar with Arduino coding but you could simulate this with something like the following (written in a pseudo-code).

You would need to set a seed number in a 16 bit register first.
The output would be the 16 bit value of the register.

MAIN :
Logical shift left register
Bit 0 = (Bit 15 XOR Bit 6) XOR (Bit 12 XOR Bit 4)
Read register
goto MAIN

This would give you a series of pseudo-random numbers. If this was full-sequence it would repeat after 65536 shifts, but my randomly chosen feedback points would possibly fall into a shorter sequence.

(On a Picaxe you would use the RANDOM command, which would give a 16 bit PRN from an initial seed value each time it was called.)
I nominate for best answer
For the second bit, take a chunk of 7 bits and convert to BCD (ignore anything over 99), then to 7 segment outputs. Couple of lookup tables required here.
Making REALLY random numbers can't be done readily by a program running in a computer without extra hardware, or cunningly getting something random.
You need something to add real uncertainty to the system. Classic methods use noise generated in a transistor.
Here's a classic circuit and process.
http://www.cryogenius.com/hardware/rng/