i want to build a program in Python designed for generating hazard numbers in lotto. For example from 1 to 45 , i want that every number between 1 and 45 ( 1 and 45 included) have the same chance to appear or not, like in real life.
What is ( or what are) the appropriate random that can do that or closer to do that (approximation).
EXEMPLE
value= random.randint(1,46)
Does all the numbers between 1 and 45 have the same chance to appear or to not appear like in reel world ?
Does chance in computer world is like chance in reel world, if no , how to make it closer?
It is not about duplication.
Thank you for helping
Asked
Active
Viewed 627 times
-2

Moneym Brussel
- 19
- 6
-
`from random import randint` then `randint(1, 45)` – James Dec 26 '20 at 14:18
-
Yes, all numbers should have the same chance. If that is not so, that would be a serious bug in the underlying random number generator. If you want to test it, simply repeatedly generate random numbers and count the occurrence of each. After a few million numbers, you should not be able to see statistically significant differences. – deceze Dec 26 '20 at 14:36
1 Answers
2
You want to sample k numbers, without replacement, from a discrete uniform distribution on the interval [1, 45].
Let's say you want to pick 6 numbers. Then write
import random
winners = random.sample(range(1, 46), k=6)
Then winners
will be a list of six randomly chosen numbers.
Explanation:
range(1, 45)
represents the interval [1, 45). In other words, it wouldn't include 45. So the second argument is 46.sample
chooses k numbers from that range of 45 without replacement. In other words, just like in the typical lottery, no number will be chosen twice — which you can't count on with otherrandom
module functions.- The distribution will be uniform by default; each number is equally likely to be chosen.

Noah
- 417
- 1
- 5
- 10