# Random 0/1 generation?

Discussion in 'Electronic Design' started by Chaos Master, Oct 16, 2003.

1. ### Chaos MasterGuest

Hi!

I want to make a device that randomly generates a 0 or 1(heads/tails). What IC's
could I use? Or a microcontroller is better?

Thanks.

2. ### MikeGuest

If you want a standalone device, noise diodes and zener diodes are often
used to generate noise. Amplify it up and sample it, and you can get a
virtually random noise source. In the simple digital department, you could
also use a Linear Feedback Shift Register (look for more information at
Xilinx). It's a simple state machine, so it's far from random (if you know
the last N bits out of an N bit LFSR, you can predict all future bits), but
it might be adequate. If someone has to push a button to show the head or
tail, then a simple clock (a few kHz is adequate) and a T flip-flop should
work well enough: stop the flip-flop when the button is pressed, and
display the state. If you use a microcontroller, you could program just
about any algorithm you want to.

-- Mike --

3. ### Jacques FournierGuest

You can use a 24-bit shift register (B23 ... B0) where the input =
(B23 XOR B22) XOR (B21 XOR B16)
The output can be any bit of the register. I used B0.
The speed of the bit output is equal to the clock frequency.
Important : before running the register hexa value must be different
of 000000 and different of FFFFFF. I choose 555555.

I used an Atmel AVR Tiny11 microcontroller. Only a few lines of
software is necessary to compute this algorithm.

Jacques

4. ### AndreGuest

Use a PIC with more than one output, run four shift registers out of
sync, and then use the outputs of those four to select one of the
random bits stored in a table in the program memory ?

5. ### MikeGuest

If you check, you'll find that your shift register contents will equal
FFFFFF at some point. The only value that won't occur is 000000. So, FFFFFF
is a valid starting point.

If you aren't committed to 24 bits, you could save a few gates by
implementing a 23 bit or 25 bit LFSR - they only require a single XOR.

-- Mike --

6. ### RobGuest

It just so happens that I've put one of these together for a project I
was working on. Generates an output which randomly switches between 0
and 1.
Rob

7. ### ChrisGuest

If all you want is a "heads/tails" indicator, set up a 555 as a 100
KHz oscillator. Use a N.O. pushbutton to switch the output into the
clock of a D flip flop set up as a toggle (connect the Q! output to
the data input). Since the pushbutton will always be pressed for a
different amount of time, the Q output of the D FF will be random.
Use the Q and Q! outputs to drive transistors, which drive your

Do a google on "electronic coin toss" (without quotes) for several
circuits of this type.

Kits are also available from Ramsey Electronics and most of the other
kit manufacturers for heads/tails projects. Sci.electronics.basics is
a better forum for questions of this type.

Good luck.
Chris

8. ### JeffMGuest

google on "electronic coin toss" (without quotes)
or, even better, with quotes.

9. ### Chaos MasterGuest

Rob engraved with a +2 athame:

- please apply ROT13 to discover a valid e-mail.

10. ### Chaos MasterGuest

Chris engraved with a +2 athame:

[snip the solution for a random 0/1 generator]
Thanks for help from everybody.
Thanks for pointing me to S.E.B.

11. ### Jacques FournierGuest

You're right. The register runs properly with FFFFFF as start value
and stays still with 000000.

12. ### Wim TonGuest

You can use a 24-bit shift register (B23 ... B0) where the input =

This is not random, but pseudo-random. It has all the properties of a random
signal in distribution of values etc, except that it is totally predictable.

It is fine for stimuli or measurements, but not for security.

Wim

14. ### Joe LegrisGuest

There's no skewness - it's a perfectly rectangular distribution. All
2^24 - 1 states occur with equal frequencies. The mean is shifted
slightly from what it would be if all 2^24 states were available, but
that's not the same as skewness, which means asymmetry

16. ### Richard HenryGuest

Interesting statement.

17. ### N. ThorntonGuest

Re random 0/1 gen: a single opamp is probably the simplest option. Set
it to oscillate, nd use a push button or an incoming 0/1 to permit
oscillation. Whatever state it settles on when osc stops is your
output.

To control the osc with a logic input, as opposed to a switch, just
put the control in line to the opamp input thru a diode. Vola.

Regards, NT

PS the lower the capacitor stability the better if very predictable
triggering pulses are used. Keep osc freq high relative to trig pulse
length to maintain randomness.

18. ### Wim TonGuest

A common circuit is a ring oscillator with an odd number of invertors, the
seem to be quite noisy.

Wim