-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomorg.py
64 lines (55 loc) · 1.46 KB
/
randomorg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import requests
import json
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import random
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
# Replace YOUR_API_KEY with your actual API key
api_key = 'APIKEY'
url = 'https://api.random.org/json-rpc/2/invoke'
headers = {'content-type': 'application/json'}
payload = {
'jsonrpc': '2.0',
# 'method': 'generateIntegers',
# 'params': {
# 'apiKey': api_key,
# 'n': 1,
# 'min': 0,
# 'max': 1000000000,
# 'replacement': True
#
'method': 'generateDecimalFractions',
'params': {
'apiKey': api_key,
'n': 1,
'decimalPlaces': 10
},
'id': 1
}
response = requests.post(url, verify=False, data=json.dumps(payload), headers=headers).json()
random_numbers = response['result']['random']['data']
# print(random_numbers[0])
random_float = random.uniform(0.0, 1.0)
rounded_float = round(random_float, 10)
# print(rounded_float)
rounded_float=1
finalNumber = random_numbers[0]*rounded_float
print(finalNumber)
if finalNumber < 0.5:
print("Heads")
else:
print("Tails")
"""
if finalNumber < 0.166667:
print("1")
elif 0.166667 < finalNumber < 0.333333:
print("2")
elif 0.333333 < finalNumber < 0.5:
print("3")
elif 0.5 < finalNumber < 0.666667:
print("4")
elif 0.666667 < finalNumber < 0.833334:
print("5")
else:
print("6")
"""