NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Project Help and Ideas » NerdKits RNG (Random Number Generator)
April 09, 2009 by wayward |
This is the very first thing I made with ATmega128 and parts in the NerdKit. Being a programmer, naturally I felt more at home with playing with the code itself than rewiring the components. The code below is a very simple modification of the "tempsensor" project, included with your NerdKit. Instead of measuring temperature, it picks up the noise from the ADC (analog-to-digital converter), amplifies it, and generates an almost truly random 16-bit number. This value can then be used as the seed for the pseudorandom number generator in stdlib (for all you C folks out there). What you will use this for is entirely up to your imagination. :) The code is commented throughout, but feel free to post questions. Zoran P.S. You will get "unused variable" warnings during compilation; they can be ignored. P.P.S. I can't test the code at the moment, I am fiddling with the LCD, but it should work. Let me know if it doesn't. :)
|
---|---|
April 09, 2009 by wayward |
Very very interesting. I see only now that there is already one "hardware number generator" among the NerdKits projects. There wasn't one when I set out to write this. Oh well... :) |
April 09, 2009 by hevans (NerdKits Staff) |
You are right, a few months back we made a similar project to yours, but we only put it up as possible project and never made any tutorial around it, so I'm sure this post will help lots of people. On another note, you mentioned that the seed you generate could be used to seed a pseudo random number generator. Another possible application we have thought of for this kind of program is to send the number generated back to the PC via the USB connector. The number could then be added into the Linux entropy pool. If you put this in a loop you could leave a NerdKit hooked up to your Linux box to make sure that any calls to /dev/random/ have plenty of entropy to work with even if you are not actively moving the mouse or touching any of its usual sources of randomness. Humberto |
April 09, 2009 by wayward |
Good idea, Humberto. I almost want to throw away my old PGP keypairs and generate new ones. :) Another simple, but rather cool application would be a truly random electronic die, with 7 LEDs tied in 4 pairs plus one in the center. Or with the LCD, DIP switches to select the number of the sides on the "die", and the big switch to roll, make a universal die -- from 1d1 to 1d127. D&D fans can boast at their next RP session. |
April 09, 2009 by thervey |
Wayward, this is pretty close to a project that I started working on. I used the included dip switch to be able to select any of the standard dice and used the temp sensor to generate a seed for the rand functions in stdlib. The only problem was that rand was generating very random numbers. My d20 would always roll like 4, 9, or 17. Haven't quite figured out what is going on with that though. Once I get it working I'll post the details. |
Please log in to post a reply.
Did you know that a NerdKit can take control of a remote-controlled car? Learn more...
|