0

I wrote this code to split a big number into smaller parts in a certain range. Now i am trying to randomize it but I'm not sure what module to use in random function and I'm stuck. Pardon my English

import random
op = ''
start = 664613997892457936451903530140172288
step = 9223372036854775808
stop = 1329227995784915872903807060280344575

while start <= stop:

  print( hex(start).lstrip("0x") + ':' + hex(start+step).lstrip("0x") )
  start += step
f = open("op.txt", "a")
f.write(op)
f.close()

The start is 800000000000000000000000000000 in hexadecimal, the stop is FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF and the difference between each step is 8000000000000000 in hexadecimal. When I run the code the numbers are generated in sequence like this:

800000000000000000000000000000:800000000000008000000000000000
800000000000008000000000000000:800000000000010000000000000000
800000000000010000000000000000:800000000000018000000000000000
800000000000018000000000000000:800000000000020000000000000000
800000000000020000000000000000:800000000000028000000000000000
800000000000028000000000000000:800000000000030000000000000000
800000000000030000000000000000:800000000000038000000000000000
800000000000038000000000000000:800000000000040000000000000000
800000000000040000000000000000:800000000000048000000000000000
800000000000048000000000000000:800000000000050000000000000000
800000000000050000000000000000:800000000000058000000000000000
800000000000058000000000000000:800000000000060000000000000000
800000000000060000000000000000:800000000000068000000000000000
800000000000068000000000000000:800000000000070000000000000000
800000000000070000000000000000:800000000000078000000000000000
800000000000078000000000000000:800000000000080000000000000000
800000000000080000000000000000:800000000000088000000000000000
800000000000088000000000000000:800000000000090000000000000000
800000000000090000000000000000:800000000000098000000000000000
800000000000098000000000000000:8000000000000a0000000000000000
8000000000000a0000000000000000:8000000000000a8000000000000000
8000000000000a8000000000000000:8000000000000b0000000000000000
8000000000000b0000000000000000:8000000000000b8000000000000000
8000000000000b8000000000000000:8000000000000c0000000000000000

Is it possible to generate random values between 800000000000000000000000000000 and FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF but with same step (8000000000000000 ) value, where the numbers generated are random, not in sequence?

I tried using random.randint(start,stop) but it just doesn't seem to work.

I am trying to achieve my output from

800000000000000000000000000000:800000000000008000000000000000
800000000000008000000000000000:800000000000010000000000000000
800000000000010000000000000000:800000000000018000000000000000
800000000000018000000000000000:800000000000020000000000000000
800000000000020000000000000000:800000000000028000000000000000
800000000000028000000000000000:800000000000030000000000000000
800000000000030000000000000000:800000000000038000000000000000
800000000000038000000000000000:800000000000040000000000000000
800000000000040000000000000000:800000000000048000000000000000
800000000000048000000000000000:800000000000050000000000000000
800000000000050000000000000000:800000000000058000000000000000
800000000000058000000000000000:800000000000060000000000000000
800000000000060000000000000000:800000000000068000000000000000
800000000000068000000000000000:800000000000070000000000000000
800000000000070000000000000000:800000000000078000000000000000

to

b4459257eda6b45af82611586bf8c6:b4459257eda6b48000000000000000
ca60da4d4a4ee38000000000000000:ca60da4d4a4ee31000000000000000
c8572366d667810000000000000000:c8572366d667818000000000000000
e5dc56311189018000000000000000:e5dc56311189020000000000000000
a324eb157a00e20000000000000000:a324eb157a00e28000000000000000
ff5b961d3b87d28000000000000000:ff5b961d3b87d30000000000000000

I'm sorry I had to put in examples, I just wanted to make sure that everyone understood my question as my English is bad.

Michael Ruth
  • 2,938
  • 1
  • 20
  • 27
Melwyn
  • 1
  • 1
  • Are you asking for https://docs.python.org/3/library/random.html?highlight=random#random.randrange ? – Sören Nov 19 '22 at 21:43
  • no I'm trying to archive random numbers. not sequential like I've showed in the above output – Melwyn Nov 19 '22 at 21:51
  • Let's be clear here: what's being generated above aren't even pseudo-random numbers. What do you want? The way I read this, you want the same numbers as in your question but shuffled so that they aren't all sequential. Is this correct? – Michael Ruth Nov 19 '22 at 21:55
  • @MichaelRuth yes sir you are correct – Melwyn Nov 20 '22 at 22:11
  • Are duplicate values acceptable, or must the values be unique? – Michael Ruth Nov 21 '22 at 17:01

1 Answers1

0

Convert your hexadecimal start and stop to decimal then use random.randint(start,stop) to generate a random number. Convert it back to hexadecimal afterwards.

Convert hex string to integer in Python

user7644509
  • 130
  • 9
  • OP already has decimal start and stop values. If this is the answer, I'm even more confused, what the question was. – Sören Nov 19 '22 at 22:15