I want to make a random number generator that allows the user to provide a hexadecimal seed value in the form of a string. I am working in C#.
I want to have as many possible valid seeds as possible.
The Random class allows us to seed it with a signed integer. I can convert the positive values to hex with ease, but what about the negative values? The maximum size for a signed int is 7FFFFFFF in hex. My ideal solution would allow me to take the entire valid range of numbers for a signed int and have a corresponding hex value for each.
Essentially, i need 2 functions that convert a given signed int to a corresponding hex value and vice versa.
My initial idea is just take any int less than 0, create an unsigned int with the value of the max value of a signed int, then add the absolute value of the int that is less than 0. Now you have a continuous range for your integer values. Convert this to hex and you have your hex value. Can anyone poke holes in my logic?
Aucun commentaire:
Enregistrer un commentaire