4 bit random counter

Thread Starter

2010ee179

Joined Jul 1, 2011
12
Hi guys...I have 4 bit synchronous counter that counts from 0000 to 1111.

I want to make it truly random so that it may generate random number with no sequence...

I don't want to any use programmable device to do the job....

So please tell me what can I do with this 4 bit counter to generate truly random number...
 

thatoneguy

Joined Feb 19, 2009
6,359
Hard to get TRUE randomness, but you can come close.
HCT 4060 14 bit binary counter with clock

When a button is pushed, the current value is latched onto the display. You could try pulling Pin 9 low via 1k resistor/momentary switch to stop the clock if using 4 individual LEDs for display, they'd appear continually on until momentary button was pressed.

Run LSB as MSB, skip a bit here and there, and you come close to random if the clock is fast enough, and the button presses are slow enough.

Adding the human factor and switch bounce is the only way to get as close to truly random as possible without using isotope decay or other quantum measurements. If you use another circuit to stop the clock, it'd have to be randomized also with a pseudo RNG, so there's a point where a loop would occur. With a human pushing a button, no loop.
 
Last edited:

Thread Starter

2010ee179

Joined Jul 1, 2011
12
That's a nice idea..thanks.

I want to use another circuit to stop the clock...like I want to stop it with 1 Hz square wave signal...when it goes low clock would be stopped but what if it goes high...would that clock continue??
I want when 1Hz go high there should be no clock at output, means 0000...
 

MrChips

Joined Oct 2, 2009
30,794
There is such a thing called a pseudo-random number generator. The problem is while the numbers appear to be random, the sequence repeats itself. With only 4 bits to work with, you will have a single sequence of 16 numbers.

To improve on this, you can start out with more bits and then just use 4 bits. For example, if you started with 20 bits, you would have 65536 different sequences of 16 random 4-bit numbers.

Using a clock driving a 4-bit counter that thatoneguy suggests is a simple solution to the problem.
 

thatoneguy

Joined Feb 19, 2009
6,359
That's a nice idea..thanks.

I want to use another circuit to stop the clock...like I want to stop it with 1 Hz square wave signal...when it goes low clock would be stopped but what if it goes high...would that clock continue??
I want when 1Hz go high there should be no clock at output, means 0000...
The method I described above was more of a 'hack' to brutally stop the oscillator long enough to grab a number. To get a number with a square wave, you could drive a capture latch that would set whatever bits were present when the signal went high, and hold/display them. Until the next capture. Timing may be off causing random behavior of the latch, but that's encouraged in this case, unless it causes it to display all 1's each time.

What is your overall desired purpose/function for this? To display 4 LEDs in random order, or to present a random number from 0-9 on a display, or to seed a LFSR, which is the 'normal' pseudo random number generator.

The problem with triggering it at exactly 1Hz, to a determined person capturing the data, it would be trivial to show the data isn't random at all, and is a collection of counter bits out of order. The human factor in pushing the button is what made the fast counter into a RNG, without the human, it turns into an NG with predictable outputs for any time from the starting point.
 

thatoneguy

Joined Feb 19, 2009
6,359
I must concede and use the dread phase: That is a project for a microcontroller, PIC PICduino, Arduino, PICAXE (if you like BASIC), etc.
 

Thread Starter

2010ee179

Joined Jul 1, 2011
12
:) Right
Since I am studying digital logic design, so I made up my mind to design it in this way...
Never mind...I am happy with PRNG now...its somewhat satisfactory for me.
 

SgtWookie

Joined Jul 17, 2007
22,230
The project in the YouTube video was made using all old-school logic ICs; 74xx and 4000 series, and a couple of 555 timers.

The "random numbers" were generated using a counter rapidly clocked by one 555, and latched by another. As already mentioned, the numbers won't be truly random. It might help to make them more random by using a pull-up resistor from pin 5 of the counter-clocking 555 to +V; this will make the threshold more sensitive to noise. It will also slow the counter down, so the timing cap or resistor may need to be reduced somewhat.
 
Top