Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Random #s

Status
Not open for further replies.
Hi all, I want to code a slot machine game (in pic ASM) And I was wondering if there was any way to get true random numbers from the pic.

Getting truly random numbers is not simple. Proper random number generators have to spend quite a bit of time gathering what's known as "entropy" which is then used to generate random numbers, and even then they are not mathematically perfect. For the most part, people settle for pseudo-random.

Try reading the following for more information: https://en.wikipedia.org/wiki/Random_number_generator

That said, 15 seconds on Google turned up a whole bunch of pseudo-random number generators for the PIC. Try something like https://www.phanderson.com/PIC/16C84/random.html and see if you're happy with the results.


Torben
 
As stated, True random numbers from machines are near impossible, or at least incredibly complex. Many of the machines that generate "random" numbers use a sort of medium to get a random value, such as pudding or custard.
 
Hi all, I want to code a slot machine game (in pic ASM) And I was wondering if there was any way to get true random numbers from the pic.

Because the game may involve the player pressing buttons, you could get a fairly random number by just reading the value of a fast cycling counter whenever a button is pressed.
 
The Jan 08 Nuts and Volts has an article on the Microchip uDice board. So check out the random number algorithm there (coding is in C). Or perhaps check the uDice docs at Microchip, they usually have asm code.
 
Because the game may involve the player pressing buttons, you could get a fairly random number by just reading the value of a fast cycling counter whenever a button is pressed.


I guess I could. But in BASIC there is a random # instruction, I was kinda wondering what it does to get it.


Thanks for all the replies!
 
Because the game may involve the player pressing buttons, you could get a fairly random number by just reading the value of a fast cycling counter whenever a button is pressed.

Very true. With a counter that is counting in the millionths of a second, it is impossible for the player (unless he hacks the thing) to influence the results.
 
Very true. With a counter that is counting in the millionths of a second, it is impossible for the player (unless he hacks the thing) to influence the results.

Thanks, I'll just use this, thanks all for the replies.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top