Anonymous user
Pseudo-random numbers/PCG32: Difference between revisions
→Python: As generator: Generates floats as well as ints.
(→{{header|Python}}: Add generator version.) |
(→Python: As generator: Generates floats as well as ints.) |
||
Line 968:
===Python: As generator===
<lang python>
def next_int():
"return random 32 bit unsigned int"
Line 996 ⟶ 990:
while True:
yield next_int() if as_int else next_int() / (1 << 32)
Line 1,005 ⟶ 999:
print(i)
hist = {i:0 for i in range(5)}
for i in islice(pcg32(987654321, 1, as_int=False), 100_000):
hist[int(i
print(hist)</lang>
|