|
1 | 1 | # imports |
2 | | -import time |
3 | | -import math |
| 2 | +import time; |
| 3 | +import math; |
4 | 4 |
|
5 | 5 | # parameters |
6 | | -seed = int(round(time.time() * 1000)) |
7 | | -multiplier = 25214903917 |
8 | | -increment = 11 |
9 | | -modulus = pow(2, 48) |
| 6 | +seed = int(round(time.time() * 1000)); |
| 7 | +multiplier = 25214903917; |
| 8 | +increment = 11; |
| 9 | +modulus = pow(2, 48); |
10 | 10 |
|
11 | 11 | # a float is a number with decimals |
12 | 12 | # an integer is a whole number |
13 | 13 | # a boolean is true or false |
14 | 14 |
|
15 | 15 | def randomInt(): # range [0 to 2^48] |
16 | | - global seed |
17 | | - seed = (seed * multiplier + increment) % modulus |
18 | | - return seed |
| 16 | + global seed; |
| 17 | + seed = (seed * multiplier + increment) % modulus; |
| 18 | + return seed; |
19 | 19 |
|
20 | 20 | def randomFloat(): # range [0 to 1] |
21 | | - return (randomInt() / modulus) |
| 21 | + return (randomInt() / modulus); |
22 | 22 |
|
23 | 23 | def randomIntRange(min, max): # custom range [minimum, maximum] |
24 | | - return (math.floor(randomFloatRange(min, max))) |
| 24 | + return (math.floor(randomFloatRange(min, max))); |
25 | 25 |
|
26 | 26 | def randomFloatRange(min, max): # custom range [minimum, maximum] |
27 | | - return (min + randomFloat() * (max - min)) |
| 27 | + return (min + randomFloat() * (max - min)); |
28 | 28 |
|
29 | 29 | def randomBool(chance): # chance of getting true (example: randomBool(20) has a 20% chance of returning true) |
30 | 30 | if(chance == 0): |
31 | | - chance = 0.5 |
32 | | - return (randomFloat() < chance) |
| 31 | + chance = 0.5; |
| 32 | + return (randomFloat() < chance); |
33 | 33 |
|
34 | 34 |
|
35 | 35 | # execute functions and print results |
36 | | -print("Sequence of Random Integers between 0 and the Modulus") |
37 | | -print(randomInt()) |
38 | | -print(randomInt()) |
39 | | -print(randomInt()) |
40 | | -print(randomInt()) |
41 | | -print("\nSequence of Random Floats between 0 and 1") |
42 | | -print(randomFloat()) |
43 | | -print(randomFloat()) |
44 | | -print(randomFloat()) |
45 | | -print(randomFloat()) |
46 | | -print("\nSequence of Random Integers between 100 and 250") |
47 | | -print(randomIntRange(100, 250)) |
48 | | -print(randomIntRange(100, 250)) |
49 | | -print(randomIntRange(100, 250)) |
50 | | -print(randomIntRange(100, 250)) |
51 | | -print("\nSequence of Random Floats between 60 and 70") |
52 | | -print(randomFloatRange(60, 70)) |
53 | | -print(randomFloatRange(60, 70)) |
54 | | -print(randomFloatRange(60, 70)) |
55 | | -print(randomFloatRange(60, 70)) |
56 | | -print("\nSequence of Random Booleans with a chance of 30% of getting true") |
57 | | -print(randomBool(0.3)) |
58 | | -print(randomBool(0.3)) |
59 | | -print(randomBool(0.3)) |
60 | | -print(randomBool(0.3)) |
| 36 | +print("Sequence of Random Integers between 0 and the Modulus"); |
| 37 | +print(randomInt()); |
| 38 | +print(randomInt()); |
| 39 | +print(randomInt()); |
| 40 | +print(randomInt()); |
| 41 | +print("\nSequence of Random Floats between 0 and 1"); |
| 42 | +print(randomFloat()); |
| 43 | +print(randomFloat()); |
| 44 | +print(randomFloat()); |
| 45 | +print(randomFloat()); |
| 46 | +print("\nSequence of Random Integers between 100 and 250"); |
| 47 | +print(randomIntRange(100, 250)); |
| 48 | +print(randomIntRange(100, 250)); |
| 49 | +print(randomIntRange(100, 250)); |
| 50 | +print(randomIntRange(100, 250)); |
| 51 | +print("\nSequence of Random Floats between 60 and 70"); |
| 52 | +print(randomFloatRange(60, 70)); |
| 53 | +print(randomFloatRange(60, 70)); |
| 54 | +print(randomFloatRange(60, 70)); |
| 55 | +print(randomFloatRange(60, 70)); |
| 56 | +print("\nSequence of Random Booleans with a chance of 30% of getting true"); |
| 57 | +print(randomBool(0.3)); |
| 58 | +print(randomBool(0.3)); |
| 59 | +print(randomBool(0.3)); |
| 60 | +print(randomBool(0.3)); |
0 commit comments