- Home /
Is there a way to create a real true random number in Unity?
Can you generate a really true (non-pseudo) random numbers with Unity for instance for use of casino and gambling related games?
The simple answer is NO.
It's inconceivable the "relatively basic" random systems on a home device (PC or tablet) would be good enough for like, the actual State Lottery.
(Note too that in "real" ga$$anonymous$$g or similar software, it is inconceivable such decisions would be made on the user's device. Of course, it's all done on the servers in Luxembourg or whatever.)
Note that when scientists look for "profoundly" random numbers they use things like physical devices (involving radioactive decay, quantum processes or whatever) that are attached to computers.
As jbarba points out, "randomness" is a very complicated mathematical topic that is poorly understood and loaded with confusion.
Tremendous confusion often arises in dealing with random numbers, a typical beginner gotchya is adding two random numbers does NOT give you a "more random" number, totally miunderstanding distributions, and so on.
If you are interested in the question you must first fully study "psuedo random number generators" ($$anonymous$$ersenne twisters and the like) and many other issues such as seeds and so on.
The "Random" routines given to you by unity are very good - use them and you're done.
OP says: "for use of casino and gambling" ....
it is utterly inconceivable you would use Unity for the actual meat of actual licensed ga$$anonymous$$g, in any jurisdiction.
It's a game engine for goodness sake, it's for making things like angry birds.
your question would be literally like asking:
"I work for Chase $$anonymous$$anhattan bank. Can I use Unity to run Chase's online banking?"
Your question is just utterly, utterly, outside the bounds of reality. The answer is "of course not, not in any way."
So what is this: https://unity3d.com/unity/industries/gambling do you think? Hmm? ;)
Answer by whydoidoit · Mar 30, 2013 at 10:07 AM
Creating truly random numbers in Unity is not possible. Creating additional randomness can be managed by incorporating unpredictable factors into the random number sequence - it's never going to be casino level quality and should not be used for gambling games, but it can remove "sameness" in other random sequences - for example the creation of mid level security keys, codes and seeds for a subsequent sequence.
Use the current time as part of the calculation - if the user is responsible for triggering an action that will need a random number it will be very unlikely that they will execute the action at a regular interval.
Use the positional movements of the mouse on a PC or the accelerometer on a device over time to adjust the random sequence
Use the Ping time to a remote server
Using current time is actually predictable... :P
The mouse position might not be so "volatile" on a server, a good idea would be using microphone's input as a perturbation to the random function.
At the millisecond level - time between events is not predictable if the user is involved in the process - I guess you mean it can be spoofed, which is true. All of these suggestions are client side though, to create a seed, which is itself down to, as I mentioned, getting the user to be more secure.
If the construction of a key is in the users best interests- i.e. security, then you are adding their deliberate unpredictability.
I guess if he had wanted a client side solution, pseudorandom numbers would have been enough...
So I am answering the question in the title - because this is a knowledge base and that is what future searchers will find. $$anonymous$$y answer is specifically not for gambling games and is for the use of factors to create additional levels of randomness.
I don't see server side specified in the question.
Answer by hoy_smallfry · Mar 29, 2013 at 11:42 PM
This is a loaded question.
The definition of "random" is arguable.
It's not possible to get "true" random numbers from a computer, by the very definition of how computers work at the low-level.
What you are actually asking for is, "How do I get numbers that look like they are purely random and/or don't repeat themselves often?"
Despite what most people think, video gambling games are deterministic, meaning the results of a move are predetermined. Therefore, using a PRG is exactly what you need.
All that said, if you are looking for PRG that "looks" random, you should do a web search for "Mersenne twister", and hopefully you can find an implementation of it in your language of choice.
Cheers!
This, is technically not true, at least not anymore. Computers are capable of generating true random numbers. However, this does require some more specialized equipment than most computer owners have.
mersenne twisters have nothing to do with anything. they just produce a sequence based on a seed. the whole issue is getting a seed.
"Computers are capable of generating true random numbers" this is "technically" (what does that mean?) not true. "computers", as such, can't generate a profoundly random seed. you have to attach a dongle which generates profound randomness using radioactive decay or the like.
Yes, it is true. A dongle is a computer. If you use it to create true randomness, then it is indeed a computer generating truly random numbers. Anything that processes and manipulates data, no matter what that data is or where it comes from, is a computer. You seem to have forgotten that a PC, or "computer" is actually made up of numerous other "computers" all hooked to one another, and communicating data back and forth. An attached dongle is a part of the computer, and thus it is the computer generating profound randomness.
"mersenne twisters have nothing to do with anything. " Your right, because "mersenne twisters " is a PRNG method, and I am not talking about mersenne twisters anyway. $$anonymous$$ake sure you actually read my source before commenting, as it might clear some confusion up and shed light on where I am co$$anonymous$$g from. ;)
If a computer uses atmospheric noise to generate numbers, how is this not a truly random number generator?
I mean, sure, the computer might still use a predictable algorithm to generate a number, but the seed used is truly random, which means the numbers that get generated will be truly random. Saying otherwise is akin to saying that rolling a die (the "seed") is not truly random because all humans follow the same "algorithm" for die rolling (take die into hands -> fold hand around die -> Loop "Shake hand" for X amount of time -> throw die onto table-> output result). No, what makes it random, is that you do not know the output, and can't figure it out without some how "hacking", or "cheating" the system (like hacking the TRNG, or using a loaded die in the analogy I made).
""technically" (what does that mean?)" If you need to know what a word means, I highly suggest you Google it, or get a dictionary for assistance. :P
Side note: Technically, our brains are biological computers, and we created dice, and playing cards, another example of a computer creating true randomness! :P
The thing that generates the randomness is a bit of radioactive material, or similar.
Computers, per se, are totally deter$$anonymous$$istic.
When I mentioned mersenne twisters, I was not addressing you, but the other person.
Don't try to talk in a overly smart, complex, phrases.
Answer by Loius · Mar 30, 2013 at 12:06 AM
"return winCon-Random.Range(1,winCon)"
^_^
I took the liberty of elevating this to an answer because: it is absolutely correct.
Answer by bruce965 · Mar 30, 2013 at 08:55 AM
Generating true random numbers requires specialized hardware, you can buy or craft a quantum random generator that produces values that cannot be predicted (according to universe physics rules).
This is an example that you can buy online.
http://www.idquantique.com/index.php?option=com_content&view=article&id=9
And this is a guide to craft a simple one, you might need a radioactive material to generate a fast enough stream of random numbers (if potassium isn't fast enough).
http://m.instructables.com/id/Arduino-True-Random-Number-Generator/
Good luck with your project, Fabio Iotti.
excellent product link, thanks. things have changed since my day! only 1000 bucks or so as well.
Answer by Desertleaf · Sep 22, 2020 at 10:59 PM
To generate true randomness you need randomizing what was already randomized and multiply that all by however many times you want to randomize to continue to randomize it.
If you had to pick a number out a bowl, no matter how shuffled the numbers, the values on top of the pile will always have the highest ratio of being chosen. Now if you change how deep to dig your hand, these values at such depth have a high ratio of being selected.
If you want true randomness, the values in the bowl need to continuously change as well as the heights of the hand that will dig in the pile before choosing.
Random is not at all as complicated as people believe it to be.