random number
Grzegorz Staniak
gstaniak at gmail.com
Mon Mar 26 03:50:06 EDT 2012
On 26.03.2012, Steven D'Aprano <steve+comp.lang.python at 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?
GS
--
Grzegorz Staniak <gstaniak _at_ gmail [dot] com>
More information about the Python-list
mailing list