Check out this cool random number generator for the pic16f690 ;)

Thread Starter

johnnyinwa

Joined Jun 24, 2013
61
Heh guys,
I have completed a project in C for the pic16f690. The project was written with the xc8 compiler (free) and the MPLABX IDE (free). The circuit generates three random numbers from one to 6 and makes two five second voice comments on a roll less than seven and triples. My hardware tool was a pic eight bit programmer from futurlec. Anyway its a cool little circuit and only uses two chips. Jameco sells a regulated wall wart putting out 5 volts at 500 mAmps but this solution is expensive -- I would advise you to score a wall wart from a surplus store. Anyway it works. Any comments you have on the circuit would be welcomed -- have fun!
 

Attachments

Wendy

Joined Mar 24, 2008
23,421
No additional information forthcoming, I am moving this thread to the Projects Forum. If the TS finishes the requirements needed I will be glad to move it back to the Completed Projects Forum, and this post will be removed.
 

Thread Starter

johnnyinwa

Joined Jun 24, 2013
61
Once again I apologize for not following the rules. Anyway I have tested the circuit extensively and it is extremely random. The random number seed for the three random numbers changes every time the button is pressed. (check this out in the code I posted). This is my first completed project using a microcontroller and I am really proud of it. I hope this answers your question. :)
 

Papabravo

Joined Feb 24, 2006
21,225
Once again I apologize for not following the rules. Anyway I have tested the circuit extensively and it is extremely random. The random number seed for the three random numbers changes every time the button is pressed. (check this out in the code I posted). This is my first completed project using a microcontroller and I am really proud of it. I hope this answers your question. :)
I am unimpressed by the qualitative statement you offered without any supporting evidence. Do you have any idea what statistical tests you might apply to your random number generator to convince me of your claim that is is extremely random? Extraordinary claims require extraordinary proof -- which in your case appears to be lacking.
 

nsaspook

Joined Aug 27, 2009
13,279
It's a great project but the 'random' number generator routine is weak and building good ones is a very specialized art so it's nothing to feel unproud about if someone says it's weak. The only real source of randomness is the operator of the button. That's OK for learning how to program a controller but I would think about another entropy source independent of the button push to mix with the seed to stop a very easy timing attack on your generator if you want to use it for an automated process to generate numbers.
http://www.microchip.com/forums/m823513.aspx
 

DerStrom8

Joined Feb 20, 2011
2,390
All "random" functions I have found require some constantly changing "base" value. On computers, I've found this is generally done using the clock. In your case, if you have an unused analog input on your PIC, you could take an ADC reading from that and use it as your "base" value for the random number generator function. The analog input would read the thermal noise and come up with some value to use as your base. Not sure how good this would be (depends on the resolution of the ADC and how you program it), but may be worth pursuing.

Just a thought. Generating random (well, pseudo-random) numbers is a very difficult task. When I was first starting to play with electronics I had a 555 and a 4017 counter. My goal was to flip through the outputs of the 4017 and stop at a "random" output. I connected my 555 timer (used to generate the clock for the 4017) to V+ through a switch, and put a large capacitor directly between pin 8 and ground. When I pressed the switch the 555 turned on and started flipping through the 4017 outputs. At the same time, it started charging the capacitor. When I let go of the button, the capacitor would keep powering the 555 until the voltage was not high enough, and the 555 would turn off. At this point the 4017 outputs would stop changing.

Unfortunately this greatly relied on the operator's button-press timing, and was not very "random".

Matt
 

Art

Joined Sep 10, 2007
806
A pic these days, timing the duration of a button press should be random enough.
You can hardly stop a stopwatch (centiseconds) where you want, let alone a smaller time division.

.
 

Papabravo

Joined Feb 24, 2006
21,225
Herein lies the problem. Just because your intuition tells you a process should be random doesn't make it so. There are quantitative tests that allow you to specify different degrees of randomness, but there is no algorithmic means of generating random numbers.
 

RichardO

Joined May 4, 2013
2,270
Herein lies the problem. Just because your intuition tells you a process should be random doesn't make it so. There are quantitative tests that allow you to specify different degrees of randomness, but there is no algorithmic means of generating random numbers.
Donald Knuth wrote "the" book on creating and verifying pseudo random numbers:

Volume 2 of "The Art of Computer Programming" is about random numbers and also about relearning one of the three Rs from grade school, viz. arithmetic. Each topic gets one chapter.
 

nsaspook

Joined Aug 27, 2009
13,279
Donald Knuth wrote "the" book on creating and verifying pseudo random numbers:

Volume 2 of "The Art of Computer Programming" is about random numbers and also about relearning one of the three Rs from grade school, viz. arithmetic. Each topic gets one chapter.
And he wrote

"The moral of the story is that random numbers should not be generated with a method chosen at random."
 
Top