Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 8th November 2004, 07:49 PM   (permalink)
Default A Random Question

Using PICs: What methods can I use to generate a random number?

What are the advantages and disadvantages of the methods in terms of Processing cost and randomness of number.

Thanks
John
__________________
The first rule of mstechca club is do not talk about mstechca club.
http://www.electro-tech-online.com/s...induser&u=1245
2camjohn is offline  
Old 8th November 2004, 08:01 PM   (permalink)
Default Re: A Random Question

Quote:
Originally Posted by 2camjohn
Using PICs: What methods can I use to generate a random number?

What are the advantages and disadvantages of the methods in terms of Processing cost and randomness of number.
You don't generally get 'random numbers', your PC can't do it either!.

What you usually get is a sequence of numbers based on a mathematical formula - in order to start it you need a random seed value, if you start with the same seed value you will get the same sequence. You then have the problem of generating a 'random' seed value to seed your 'pseudo' random number generator. Rather like the 'chicken and egg' question :lol:

How I usually do it is to use a PIC timer running very fast, the PIC program waits for a key press - when the key is pressed the random seed is initialised with the value from the timer registers.

As usual, look on the PICList for examples! - or in the PIC Source Code Book, available free online at Dontronics (which is the one I use).
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 9th November 2004, 12:18 AM   (permalink)
Default

One of my favorite instances of the "pseudo" in pseudo random number generators comes from Las Vegas. A group of techies watched all the numbers in a game called keno and figured out which random number generator was being used. They used this to compute the next 6 numbers and win getting 6 out of 6 numbers. Unfortionately for them no one had ever gotten all 6 numbers and given that they won the first time they ever played the game it looked really suspect and they were caught.

You can sample the noise coming from a diode or resistor which idealy is random.

You could use uninitialized Ram locations for your seed. At startup, ram takes on fairly random patterns.
bmcculla is offline  
Old 9th November 2004, 01:04 AM   (permalink)
Default Re: A Random Question

Quote:
Originally Posted by 2camjohn
Using PICs: What methods can I use to generate a random number?

What are the advantages and disadvantages of the methods in terms of Processing cost and randomness of number.

Thanks
John
what is the definition of random..sounds like a good thread title...i woudl say never can be repeated, right...
well this is my random number generator---i had a 20MHz IC clock hooked up to four counters.. when a button was held down the clock was connected to the counters, when the button was let go the clock was disconnected from the counters, and LEDs would show a pattern..
due to the fact that you could never push the button (on) for the same amount of time the resulting pattern would allways be different..i used twelve LEDs three groups of four..
williB is offline  
Old 9th November 2004, 01:22 PM   (permalink)
Default

This is what I was worried about.

I know that on linux you can generate true random numbers but it requires user input (say from the mouse).


I was hoping there would be a simple way of generating a quite random number (just an even spread between two values would be OK) without needing input from the user.


bmccula:
How would I go about sampling noise from a resistor or diode?


Thanks
__________________
The first rule of mstechca club is do not talk about mstechca club.
http://www.electro-tech-online.com/s...induser&u=1245
2camjohn is offline  
Old 9th November 2004, 01:36 PM   (permalink)
Default

Quote:
Originally Posted by 2camjohn
This is what I was worried about.

I know that on linux you can generate true random numbers but it requires user input (say from the mouse).
It doesn't sound like a true random number at all, it sounds exactly the same as other systems, either Windows or DOS - just a psuedo random sequence, requiring a random seed to start.

Quote:
I was hoping there would be a simple way of generating a quite random number (just an even spread between two values would be OK) without needing input from the user.
What exactly are you trying to do?.

Quote:
bmccula:
How would I go about sampling noise from a resistor or diode?
The usual method is to use a zener diode, try googling for 'white noise generator' - although I'm not sure how you will generate a number from the white noise?.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 9th November 2004, 11:24 PM   (permalink)
Default

If I remember correctly diodes create noise based on their temperature. The noise probability curve is a gaussian curve. If you roll dice the odds for a number comming up are the same for each number - a flat probability curve. With a gaussian curve the values in the middle are more probable than the values on the edges. This is the type of curve you get when you roll 2 dice and add the numbers together.

This noise is truly random becuse it results from the random movement of electrons due to heat.

As far as making a random number you just amplify the noise from the diode and send it to an ADC. I'm no expert on this though. If you spend a bit of time with google you probably will find a fair amount of info on noise generation. There is a device called a "noise diode" that is designed for noise generation - might be a good place to start your search.
bmcculla is offline  
Old 16th November 2004, 10:21 AM   (permalink)
Default I think that the best and simpler...

For any micro running fast (4 MHz should be -is - more than enough) and a user pressing two or more buttons, an 8-bit counter running continuously in the background should give random numbers. Yes, they are just 256 possible ones (not a random thing) but which one, that's random.

I used that idea in a design for training in martial arts where the trainee had to kick random lighted pads with the next always lit at random based on when he did the previous kick.

Not a big deal in code size or RAM involved. Sure nobody, even Bruce Lee, could predict which one would be next!
atferrari is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 07:47 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker