On 3/26/12 8:50 AM, Grzegorz Staniak wrote:
On 26.03.2012, Steven D'Aprano<steve+comp.lang.pyt...@pearwood.info> wroted:
How can we generate a 6 digit random number from a given number ?
what about this?
given_number=123456
def rand_given_number(x):
... s = list(str(x))
... random.shuffle(s)
... return int(''.join(s))
...
print (rand_given_number(given_number))
653421
That's not very random. In fact, it is *terrible* as a random number
generator.
But isn't it what the OP requested, i.e. "6 digit random number
*from a given number*"? That is, a random permutation of the set
of its digits?
I would consider that to be a very odd interpretation of that request. But it
*is* an extraordinarily vague request. I'm not sure if even the OP knows what he
wants. I suspect he really wants something like a hash.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
--
http://mail.python.org/mailman/listinfo/python-list