Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!eweka.nl!hq-usenetpeers.eweka.nl!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.026 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; '>>>>': 0.09; 'subject:number': 0.09; 'random': 0.13; 'print': 0.15; '*is*': 0.16; 'enigma': 0.16; 'kern': 0.16; 'received:80.91': 0.16; 'received:80.91.229': 0.16; 'received:gmane.org': 0.16; 'received:list': 0.16; 'subject:random': 0.16; 'underlying': 0.16; 'robert': 0.18; 'def': 0.20; 'wrote:': 0.21; 'i.e.': 0.22; 'odd': 0.22; 'header:In-Reply-To:1': 0.22; 'header:User-Agent:1': 0.23; '>>>': 0.24; 'this?': 0.24; 'suspect': 0.29; 'skip:( 30': 0.34; 'knows': 0.35; 'really': 0.36; "i'm": 0.36; 'sure': 0.36; 'header:X-Complaints-To:1': 0.36; 'but': 0.36; 'something': 0.38; 'received:org': 0.38; 'to:addr:python-list': 0.39; 'how': 0.40; 'to:addr:python.org': 0.40; 'request.': 0.62; 'fact,': 0.63; 'our': 0.64; 'world': 0.65; 'believe': 0.67; 'digits?': 0.84; 'generator.': 0.84; 'terrible': 0.84; 'eco': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robert Kern Subject: Re: random number Date: Mon, 26 Mar 2012 10:36:12 +0100 References: <4f7019b6$0$29968$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 94.197.127.115.threembb.co.uk User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20120313 Thunderbird/11.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1332754589 news.xs4all.nl 6855 [2001:888:2000:d::a6]:45099 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22167 On 3/26/12 8:50 AM, Grzegorz Staniak wrote: > On 26.03.2012, Steven D'Aprano 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