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

Discussion in 'Embedded Systems and Microcontrollers' started by johnnyinwa, Aug 24, 2015.

  1. johnnyinwa

    Thread Starter Member

    Jun 24, 2013
    41
    1
    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!
     
  2. johnnyinwa

    Thread Starter Member

    Jun 24, 2013
    41
    1
    I apologize for not following the thread rules guys -- please delete my post if it angers you. Sorry!! ;(
     
  3. Wendy

    Moderator

    Mar 24, 2008
    20,765
    2,535
    This project comes very close. I can fix the schematic issue and display it as an image, but we need pictures of your work.
     
    johnnyinwa likes this.
  4. Papabravo

    Expert

    Feb 24, 2006
    10,136
    1,786
    Have you tested the randomness of the random number generator? How did that work out?
     
    johnnyinwa and nsaspook like this.
  5. Wendy

    Moderator

    Mar 24, 2008
    20,765
    2,535
    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.
     
    johnnyinwa likes this.
  6. johnnyinwa

    Thread Starter Member

    Jun 24, 2013
    41
    1
    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. :)
     
  7. Wendy

    Moderator

    Mar 24, 2008
    20,765
    2,535
    Need pictures of fisished project. Beauty is not required.
     
  8. Papabravo

    Expert

    Feb 24, 2006
    10,136
    1,786
    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.
     
  9. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,907
    2,163
    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
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    True random is tricky and oft non intuitive to achieve.

    For starters go look up the US draft of 1969.
     
  11. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    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
     
  12. Art

    Distinguished Member

    Sep 10, 2007
    785
    61
    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.

    .
     
  13. BR-549

    Well-Known Member

    Sep 22, 2013
    1,981
    388
    Couldn’t you just take a register, rotate 1 thru 6, and a stop button?

    True randomness has yet to be invented.
     
    nsaspook likes this.
  14. Papabravo

    Expert

    Feb 24, 2006
    10,136
    1,786
    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.
     
  15. RichardO

    Well-Known Member

    May 4, 2013
    1,230
    382
    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.
     
  16. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,907
    2,163
    And he wrote

    "The moral of the story is that random numbers should not be generated with a method chosen at random."
     
    ErnieM and RichardO like this.
Loading...