Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #22162

Re: random number

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news-peer.in.tum.de!news.belwue.de!news.uni-stuttgart.de!news.nask.pl!news.nask.org.pl!news.internetia.pl!not-for-mail
From Grzegorz Staniak <gstaniak@gmail.com>
Newsgroups comp.lang.python
Subject Re: random number
Date Mon, 26 Mar 2012 07:50:06 +0000 (UTC)
Organization Netia S.A.
Lines 25
Message-ID <jkp73e$9qd$1@mx1.internetia.pl> (permalink)
References <CABgq=FyhR+Ldujj3YKRBpVXRVoeoayuXZviUUcNx-gXnFiHLSw@mail.gmail.com> <mailman.980.1332744526.3037.python-list@python.org> <4f7019b6$0$29968$c3e8da3$5496439d@news.astraweb.com>
NNTP-Posting-Host 62.244.149.216
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Trace mx1.internetia.pl 1332748206 10061 62.244.149.216 (26 Mar 2012 07:50:06 GMT)
X-Complaints-To abuse@inetia.pl
NNTP-Posting-Date Mon, 26 Mar 2012 07:50:06 +0000 (UTC)
X-Tech-Contact usenet@internetia.pl
User-Agent slrn/0.9.9p1 (Linux)
X-Server-Info http://www.internetia.pl/
Xref csiph.com comp.lang.python:22162

Show key headers only | View raw


On 26.03.2012, Steven D'Aprano <steve+comp.lang.python@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>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: random number Michael Poeltl <michael.poeltl@univie.ac.at> - 2012-03-26 08:40 +0200
  Re: random number Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-26 07:24 +0000
    Re: random number Grzegorz Staniak <gstaniak@gmail.com> - 2012-03-26 07:50 +0000
      Re: random number Robert Kern <robert.kern@gmail.com> - 2012-03-26 10:36 +0100

csiph-web