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


Groups > comp.lang.python > #22165

Re: random number

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <michael.poeltl@univie.ac.at>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.034
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; 'advance.': 0.03; 'string.': 0.05; 'subject:number': 0.09; 'random': 0.13; 'print': 0.15; 'cc:addr:python-list': 0.15; 'subject:random': 0.16; 'wien,': 0.16; 'output': 0.18; 'mon,': 0.18; 'string': 0.18; 'def': 0.20; 'role': 0.20; 'wrote:': 0.21; 'passing': 0.22; 'header:In-Reply-To:1': 0.22; 'header:User-Agent:1': 0.23; 'import': 0.24; '(or': 0.24; '>>>': 0.24; 'input': 0.24; 'this?': 0.24; 'cc:no real name:2**0': 0.26; 'quite': 0.26; 'tried': 0.26; 'cc:addr:python.org': 0.27; 'pm,': 0.28; 'cc:2**0': 0.31; 'experienced': 0.31; 'maybe': 0.31; 'skip:( 30': 0.34; 'thanks': 0.34; 'skip:s 20': 0.34; "skip:' 10": 0.35; 'characters': 0.35; 'charset:us-ascii': 0.36; 'something': 0.38; 'michael': 0.38; 'skip:l 20': 0.38; 'clear': 0.39; 'how': 0.40; 'mar': 0.61; 'content-disposition:inline': 0.62; 'skip:+ 10': 0.63; 'more': 0.63; 'achieve': 0.64; '26,': 0.66; '2012': 0.69; 'materials': 0.70; '12:10': 0.84; 'one;': 0.84; 'random,': 0.84; 'voice:': 0.84; 'alphanumeric': 0.93
DKIM-Signature v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=univie.ac.at; s=rev2; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=h98oe4rtw6c7tJ6DvWsYScpaNDai4YyTolvVpRJ7gOA=; b=exzImqqmwLKeKFAF8+xYTvDhUUmIFLl4FbfEIqnlFW7NxT/GGXyTo64AAN3wWJe3cxYu2Y1lxZa/IZihRfXjGxEopEzTI0EVZgjpONY2KxDrRU8xWjNHE4hwXWsIgg2SQW2ZY8HoivuDr1tX6QUOWJUcKVLnF0yPmJpVsHVGyg0=;
Date Mon, 26 Mar 2012 11:24:03 +0200
From Michael Poeltl <michael.poeltl@univie.ac.at>
To Nikhil Verma <varma.nikhil22@gmail.com>
Subject Re: random number
References <CABgq=FyhR+Ldujj3YKRBpVXRVoeoayuXZviUUcNx-gXnFiHLSw@mail.gmail.com> <20120326064000.GB19865@terra.cms.at> <CABgq=FwMuHR1nJiaCDiTJAE4Y_3y6WRhZ2DOMaYYC=ex_gT93g@mail.gmail.com>
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
In-Reply-To <CABgq=FwMuHR1nJiaCDiTJAE4Y_3y6WRhZ2DOMaYYC=ex_gT93g@mail.gmail.com>
User-Agent Mutt/1.5.21 (2010-09-15)
X-Univie-Virus-Scan scanned by ClamAV on jarvis.univie.ac.at
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.986.1332753846.3037.python-list@python.org> (permalink)
Lines 86
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1332753846 news.xs4all.nl 6852 [2001:888:2000:d::a6]:39563
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:22165

Show key headers only | View raw


* Nikhil Verma <varma.nikhil22@gmail.com> [2012-03-26 08:49]:
> Hi
> 
> I want something to achieve like this :-
> 
> def random_number(id): # I am passing it from request
>     # do something
>     return random_number
> 
> Output
> 
> random_number(5)
> AXR670
> 
> One input that is a number in return you are getting 6 digit alphanumeric
> string.
> 
> I tried this
> s = '%06d' % random.randint(0, 999999)
> 
> it gives : '192862' (a string )
> 
> Thanks in advance.
ah - so I misunderstood - I thought you want a permutation of a given
6-digit number

It's still not quite clear to me what role 'id' is playing ... so let's
check this one;
and Steven, who is maybe more experienced than I am will help us ufrther

>>> import random, string
>>> def random_number(id):
...     characters = list(string.ascii_lowercase +
...                       string.ascii_uppercase +
...                       string.digits)
...     coll_rand = []
...     for i in range(6):
...         random.shuffle(characters)
...         coll_rand.append(characters[0])
...     return ''.join(coll_rand)
... 
>>> id = 5
>>> print (random_number(id))
puMHCr
>>>

regards
Michael


> 
> On Mon, Mar 26, 2012 at 12:10 PM, Michael Poeltl <
> michael.poeltl@univie.ac.at> wrote:
> 
> > * Nikhil Verma <varma.nikhil22@gmail.com> [2012-03-26 08:09]:
> > > Hi All
> > >
> > > 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
> >
> 
> 
> 
> -- 
> Regards
> Nikhil Verma
> +91-958-273-3156


-- 
Michael Poeltl
Computational Materials Physics      voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12         fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
-------------------------------------------------------------------------------
ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12
-------------------------------------------------------------------------------

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


Thread

Re: random number Michael Poeltl <michael.poeltl@univie.ac.at> - 2012-03-26 11:24 +0200

csiph-web