Considering the fact that set is an unordered data structure, I began to wonder if it is possible to create a truly "random" number with the usage of it (or with the usage of a dictionary).
Lets consider such an input number represented as a string:
input = "0123456789"
And then we convert the string into a set:
input_set = set(input)
After printing the result of this operation multiple times, we have following example outputs:
{'9', '3', '4', '6', '0', '7', '1', '8', '5', '2'}
{'3', '4', '2', '1', '5', '7', '0', '8', '6', '9'}
Now we can convert the elements of the set into a string with the usage of:
output = ''.join(set_input)
And the result of this operation for the sets above would be:
9346071852
3421570869
Would generation of a random number in a following way be considered a good practice?
And most of all, do I understand correctly that it would be a "pseudorandom" number, because we could reproduce the result with the usage of some seed value or key?
Aucun commentaire:
Enregistrer un commentaire