Random Bits
Ttailspin
Posts: 1,326
Trying to make a Random four bit Binary pattern, (Think Binary Coded Decimal(BCD))
This Pseudo code hopefully makes my question clear enough...
The resulting decoded 0 thru 15 will then light a random led...after being inverted by the 7404's of course.
This Circuits "normal" purpose is a Compass Ring, that uses either the HM55B or the HMC6352 Compass Modules.
However, I wish to make a Random pattern appear, to make a Light Show at start up.
Anyways, I was trying to make a random pattern, and I am to newbie to put all the pieces together...
This Pseudo code hopefully makes my question clear enough...
PUB RandomBits Bit0 := Random 1 or 0 'Make Bit 1 or 0 Bit1 := Random 1 or 0 'Make Bit 1 or 0 Bit2 := Random 1 or 0 'Make Bit 1 or 0 Bit3 := Random 1 or 0 'Make Bit 1 or 0 RandomBits := Bit0 and Bit1 and Bit2 and Bit3 'to make this >>>> %???? <<<<The output (RandomBits) goes to a 74154 (4 to 16 line Decoder),
The resulting decoded 0 thru 15 will then light a random led...after being inverted by the 7404's of course.
This Circuits "normal" purpose is a Compass Ring, that uses either the HM55B or the HMC6352 Compass Modules.
However, I wish to make a Random pattern appear, to make a Light Show at start up.
Anyways, I was trying to make a random pattern, and I am to newbie to put all the pieces together...
Comments
Because this is a pseudo-random sequence, it will repeat given the same initial value. That can be handy for debugging. If you need something more "random", you can use some kind of user input or reading the compass 100 or 1000 times and adding the values together to get a starting value. There will usually be some random noise in those values and that will give you a different starting value each time.
Still not sure how to combine all four of the "Bits" into one though. What should that code look like?
Do I shift something?
-Phil
Do you need the bits as such? If not just extract 4 bits from the LFSR, e.g. nibble := ?Rand & %1111. Otherwise it's
I know 74HC595's are more "effective" for the Compass Ring, I have that up and running allready..
But I got to thinking that maybe, one 74HC595 could control two CD4028's for 20 led's, or two 74154's, or...oh my...
Anyways, thanks for the speedy answers from everybody, I will chew on this for day's...
The bit of code you have above works by simply allowing only the lower 4 binary digits to contain a value. %1111_1111 & %0000_1111 = %0000+1111
%1111_1111 & %0110_1111 = 0110_1111, and so on.
There are truth tables in the forums here, and elsewhere online. These are well worth learning, because a lot of short cuts depend on the bitwise operators.
The Truth Tables will set You free...
All you need is one pin, one resistor, and one capacitor.
1. Put the capacitor and resistor in parallel between a pin and ground choosing values so that it will take at least 1000 clock cycles for the capacitor to drain through the resistor.
2. Set the pin to output and pull it high.
3. Set the pin to input and count the number of clock cycles it takes to transition from high to low.
4. Take the least significant bit of this counter as a coin flip.
Once you have coin flips you can generate any random number.
Thermal variations and antenna effects from the traces effectively randomize the precise clock cycle on which the logical transition occurs.
This may seem crazy when you have a pseudo random number generator available, but if you start with the same seed value every time you will get the same sequence of numbers out of the generator.
If you have human input then you can seed with the clock value at the time of the human interaction and you are good to go, but if you want to turn something on and have it do random things without any additional input then you need to have hardware randomization.
But in this particular case, It would be a bit of an "overkill", as I just needed the Illusion of randomness..
I know that I can get a very random number by just changing the seed value when i use "?", and a way
to do that is to "spin" the seed number up or down until a button us pushed, humans just aren't accurate
enough to push the button at the exact same time everytime..(well most humans anyway...)
But I do understand what You are saying if I don't have a Human to push the button..
My goal here is "Nibble Control" and this thread has brought much to light in that direction..
Thanks again for any and all info.. Just a single word is all it takes sometimes..