简体   繁体   中英

How can I generate every possible integer in a range without repeats from a seeds that is also reversible

I have been looking for a while at large number generation through seeds and I've struggled to find what I am looking for due to how specific it is. I think the main thing that is causing the problems is the size of numbers I want to generate, for example... I want to have it so that I can generate every single number that is 5000 digits long through some form of seed or selective input process. The other problem being that I would like to be able to reverse the process to know how I got there. If I have this number I want to know what inputs or what seed would generate this. Hope this makes sense and I understand this is a extremely specific question.

For a problem like this I would use an encryption. Since encryption is a one-to-one process provided you use unique inputs, and keep the same key, then the outputs are guaranteed unique. for unique inputs, encrypt the numbers 0, 1, 2, 3, ... You will need to extend the inputs by adding leading zeros so they are the size you need, enough for the binary equivalent of 5,000 decimal digits.

The output from the encryption will be the same size. Just convert the binary output back into the equivalent decimal number. There may be a few boundary cases just over the limit where the decimal and binary boundaries; in those cases just re-encrypt until the result is within the set limit. This is the cycle walking technique from Format Preserving encryption.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM