I am trying to debug this piece of code and learn a little. I learn that it generates 3 unique values for i
but how come the values of sum
become this much big?
If I run it and debug it, it goes something like this. It keep changes since values are chosen randomly.
i = 6
i = 26
i = 38
test_num = 274945015872
Output:
100000000000100000000000000000001000000
Why the value for test_num 274945015872
? It then uses this value to generate 39-bit
binary string. Like how?
Can someone explain?
Here is the code:
test_num = sum(1<<i for i in random.sample(range(1,40),3))
#left to right one bit shifting
print (print (f"{test_num:039b}"))