how do random numbers on computers work?

1.41K views

For example, is there a formula for a random number?

In: 47

75 Answers

Anonymous 0 Comments

In simplest terms they are formulas, but to get the “random” output the program uses what’s called a “seed”. This in very simple RNGs this is just the time, others will add mouse movements and button inputs to make it “feel” more random.

In the most advance ones, particularly the ones generating encryption keys, will actually use real world phenomena as parts of the seed.

Anonymous 0 Comments

[deleted]

Anonymous 0 Comments

In simplest terms they are formulas, but to get the “random” output the program uses what’s called a “seed”. This in very simple RNGs this is just the time, others will add mouse movements and button inputs to make it “feel” more random.

In the most advance ones, particularly the ones generating encryption keys, will actually use real world phenomena as parts of the seed.

Anonymous 0 Comments

In simplest terms they are formulas, but to get the “random” output the program uses what’s called a “seed”. This in very simple RNGs this is just the time, others will add mouse movements and button inputs to make it “feel” more random.

In the most advance ones, particularly the ones generating encryption keys, will actually use real world phenomena as parts of the seed.

Anonymous 0 Comments

For gaming & gambling purposes, it doesn’t matter if a number is truly random or pseudorandom. All that matters is that they are unpredictable and have no distribution bias.
Both are relatively easy to achieve by using seed numbers that no external user could possibly have access to, such as the host computer’s clock or temperature sensors (or both concurrently).

Anonymous 0 Comments

For gaming & gambling purposes, it doesn’t matter if a number is truly random or pseudorandom. All that matters is that they are unpredictable and have no distribution bias.
Both are relatively easy to achieve by using seed numbers that no external user could possibly have access to, such as the host computer’s clock or temperature sensors (or both concurrently).

Anonymous 0 Comments

For gaming & gambling purposes, it doesn’t matter if a number is truly random or pseudorandom. All that matters is that they are unpredictable and have no distribution bias.
Both are relatively easy to achieve by using seed numbers that no external user could possibly have access to, such as the host computer’s clock or temperature sensors (or both concurrently).

Anonymous 0 Comments

Some microcontrollers use “shot noise” from a spare transistor to feed their Random() statement. You could feed that into a gaming system or anything really.

Lots of formulas: [Link](https://www.physics.wisc.edu/courses/home/spring2020/623/miscellaneous%20electronics%20tips/More%20noise%20references/shot_noise_chp6_txt.pdf)

Anonymous 0 Comments

Some microcontrollers use “shot noise” from a spare transistor to feed their Random() statement. You could feed that into a gaming system or anything really.

Lots of formulas: [Link](https://www.physics.wisc.edu/courses/home/spring2020/623/miscellaneous%20electronics%20tips/More%20noise%20references/shot_noise_chp6_txt.pdf)

Anonymous 0 Comments

Complete (theoretical) randomness is hard to achieve.

Computers often generate pseudo random numbers by taking a measurable event and calculating a new value from that seed value in an attempt to give a result that behaves like a random number.

The most common approach is to use a value like the current time to calculate a number between 0 and 1. If you have special requirements for this number you need to look after them yourself.

As a simplified example, lets say I want a random number to approximate a coin flip (two options, heads or tails)

In this case you might choose heads for any value 0.5000 and above, and tails for any value below or equal to 0.4999.

If you want to simulate dice rolls (1,2,3,4,5, or 6) you might take the “random value (0 to 1), multiply by 6 and add 0.5 and then drop the part to the right of the decimal point.

If you are programming in C++ this give a [good intro](https://www.geeksforgeeks.org/rand-and-srand-in-ccpp/)