# 4 bit random counter

Discussion in 'General Electronics Chat' started by 2010ee179, Nov 22, 2011.

1. ### 2010ee179 Thread Starter New Member

Jul 1, 2011
12
1
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...

2. ### thatoneguy AAC Fanatic!

Feb 19, 2009
6,357
718
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: Nov 22, 2011
2010ee179 likes this.
3. ### 2010ee179 Thread Starter New Member

Jul 1, 2011
12
1
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...

4. ### MrChips Moderator

Oct 2, 2009
12,624
3,451
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.

jaygatsby likes this.
5. ### thatoneguy AAC Fanatic!

Feb 19, 2009
6,357
718
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.

6. ### 2010ee179 Thread Starter New Member

Jul 1, 2011
12
1
I am basically trying to do this project... http://www.youtube.com/watch?v=0SG-Ftnpjns

So I need 3 bit random address to feed a 3-8 line decoder for the very first row of LEDs...

7. ### thatoneguy AAC Fanatic!

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

8. ### 2010ee179 Thread Starter New Member

Jul 1, 2011
12
1
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.

9. ### SgtWookie Expert

Jul 17, 2007
22,183
1,728
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.