|
1 | | -def randomnum(): |
2 | | - #importing datetime module |
3 | | - import datetime #inbuilt module |
4 | | - time_now = datetime.datetime.now() |
5 | | - #getting time in terms of microseconds |
6 | | - random_seed = time_now.microsecond |
7 | | - # an equation which returns a number between 0 and 10 & takes an integer as a parameter |
8 | | - seed = random_seed * 8 % 11 |
9 | | - #making random number somewhat unpredictable !!! |
10 | | - random_micro_secs = [] |
11 | | - for i in range(seed): |
12 | | - random_micro_secs.append(time_now.second**seed) |
13 | | - seed_2 = sum(random_micro_secs) |
14 | | - #generating final random number |
15 | | - truely_random_num=(seed_2 * 8 % 11) |
16 | | - print(truely_random_num) |
| 1 | +import datetime |
| 2 | +import pytz # Required library for time zone support |
17 | 3 |
|
18 | | - |
| 4 | +def randomnum(time_zone): |
| 5 | + # Getting the current time in the specified time zone |
| 6 | + time_now = datetime.datetime.now(pytz.timezone(time_zone)) |
| 7 | + |
| 8 | + # Getting time in terms of microseconds |
| 9 | + random_seed = time_now.microsecond |
| 10 | + |
| 11 | + # An equation which returns a number between 0 and 10 |
| 12 | + seed = random_seed * 8 % 11 |
| 13 | + |
| 14 | + # Making random number somewhat unpredictable |
| 15 | + random_micro_secs = [] |
| 16 | + for i in range(seed): |
| 17 | + random_micro_secs.append(time_now.second**seed) |
| 18 | + |
| 19 | + seed_2 = sum(random_micro_secs) |
| 20 | + |
| 21 | + # Generating the final random number |
| 22 | + truly_random_num = (seed_2 * 8 % 11) |
| 23 | + |
| 24 | + return truly_random_num |
19 | 25 |
|
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
| 26 | +# Example usage |
| 27 | +time_zone = 'America/New_York' # Specify the desired time zone |
| 28 | +random_number = randomnum(time_zone) |
| 29 | +print(random_number) |
0 commit comments