Re: Random number help

2016-11-23 Thread Larry Hudson via Python-list
On 11/23/2016 11:17 AM, Thomas Grops wrote: I need a way of generating a random number but there is a catch: I don't want to include certain numbers, is this possible? random.randint(1,100) works as it will randomly pick numbers between 1 and 100 but say i don't want 48 to come out

Re: Random number help

2016-11-23 Thread Thomas Grops via Python-list
Thankyou for all your help I have managed to pick a way that works from your suggestions :D -- https://mail.python.org/mailman/listinfo/python-list

Re: Random number help

2016-11-23 Thread MRAB
On 2016-11-23 19:29, Chris Kaynor wrote: On Wed, Nov 23, 2016 at 11:17 AM, Thomas Grops via Python-list wrote: I need a way of generating a random number but there is a catch: I don't want to include certain numbers, is this possible? random.randint(1,100) works as it will randomly

Re: Random number help

2016-11-23 Thread Thomas Grops via Python-list
On Wednesday, 23 November 2016 19:30:21 UTC, Chris Kaynor wrote: > On Wed, Nov 23, 2016 at 11:17 AM, Thomas Grops via Python-list > wrote: > > I need a way of generating a random number but there is a catch: > > > > I don't want to include cert

Re: Random number help

2016-11-23 Thread Thomas Grops via Python-list
On Wednesday, 23 November 2016 19:30:04 UTC, Thomas Nyberg wrote: > On 11/23/2016 02:17 PM, Thomas Grops via Python-list wrote: > > I need a way of generating a random number but there is a catch: > > > > I don't want to include certain numbers, is this possible? &g

Re: Random number help

2016-11-23 Thread Achilleas Michailidis
You can use a while statement until you get a number out of your excluded numbers excludedNumbers = [1,2,3,4] randomNumber = random.randomint(1,100) while randomNumber in excludedNumbers: randomNumber = random.randomint(1,100) After the while you have a number outside the excluded nu

Re: Random number help

2016-11-23 Thread Chris Kaynor
On Wed, Nov 23, 2016 at 11:17 AM, Thomas Grops via Python-list wrote: > I need a way of generating a random number but there is a catch: > > I don't want to include certain numbers, is this possible? > > random.randint(1,100) works as it will randomly pick numbers between 1

Re: Random number help

2016-11-23 Thread Thomas Nyberg
On 11/23/2016 02:17 PM, Thomas Grops via Python-list wrote: I need a way of generating a random number but there is a catch: I don't want to include certain numbers, is this possible? random.randint(1,100) works as it will randomly pick numbers between 1 and 100 but say i don't

Re: Random number help

2016-11-23 Thread Marko Rauhamaa
Thomas Grops : > random.randint(1,100) works as it will randomly pick numbers between 1 > and 100 but say i don't want 48 to come out is there a way of doing > this. It needs to be an integer too so not a list unless there is a way > to convert list to int r = 48 while r == 48: r = r

Random number help

2016-11-23 Thread Thomas Grops via Python-list
I need a way of generating a random number but there is a catch: I don't want to include certain numbers, is this possible? random.randint(1,100) works as it will randomly pick numbers between 1 and 100 but say i don't want 48 to come out is there a way of doing this. It needs to be

Re: tweaking random number

2012-05-09 Thread Peter Otten
Nikhil Verma wrote: > Hi All > > I want to generate a random number of 8 digits which involve 3 number and > 5 digits. > Like this :- > > def random_number(): > # do something > > random_number() > "123abcde" # first 3 numbers and 5 letters after

Re: tweaking random number

2012-05-09 Thread Chris Angelico
On Wed, May 9, 2012 at 5:01 PM, Nikhil Verma wrote: > Hi All > > I want to generate a random number of 8 digits which involve 3 number and 5 > digits. (That's 3 digits and 5 letters) Pretty easy. Do you want to distinguish between uppercase and lowercase letters? Your curr

Re: tweaking random number

2012-05-09 Thread MRAB
On 09/05/2012 08:01, Nikhil Verma wrote: Hi All I want to generate a random number of 8 digits which involve 3 number and 5 digits. Like this :- def random_number(): # do something random_number() "123abcde" # first 3 numbers and 5 letters after the numbers. I am able to ge

tweaking random number

2012-05-09 Thread Nikhil Verma
Hi All I want to generate a random number of 8 digits which involve 3 number and 5 digits. Like this :- def random_number(): # do something random_number() "123abcde" # first 3 numbers and 5 letters after the numbers. I am able to generate the random number 8 digit like t

Re: random number

2012-03-26 Thread Ian Kelly
On Mon, Mar 26, 2012 at 3:24 AM, Michael Poeltl wrote: import random, string def random_number(id): > ...     characters = list(string.ascii_lowercase + > ...                       string.ascii_uppercase + > ...                       string.digits) > ...     coll_rand = [] > ...     for

Re: random number

2012-03-26 Thread ian douglas
On Mar 26, 2012 12:28 AM, "Steven D'Aprano" < steve+comp.lang.pyt...@pearwood.info> wrote: > > On Mon, 26 Mar 2012 08:40:00 +0200, Michael Poeltl wrote: > > > * Nikhil Verma [2012-03-26 08:09]: > A truly random six digit number will include any number between 10 > through 99. There are exa

Re: random number

2012-03-26 Thread Robert Kern
On 3/26/12 10:45 AM, Nikhil Verma wrote: Hi Thanks Michael I want exactly wanted this. Great def random_number(id) ...characters = list(string.ascii_lowercase +string.ascii_uppercase +string.digits) I used this this earlier and tried then by using choice . This is great. Note that th

Re: random number

2012-03-26 Thread Nikhil Verma
. 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 > >&g

Re: random number

2012-03-26 Thread Robert Kern
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(&#

Re: random number

2012-03-26 Thread Michael Poeltl
and) ... >>> id = 5 >>> print (random_number(id)) puMHCr >>> regards Michael > > On Mon, Mar 26, 2012 at 12:10 PM, Michael Poeltl < > michael.poe...@univie.ac.at> wrote: > > > * Nikhil Verma [2012-03-26 08:09]: > > > Hi A

Re: random number

2012-03-26 Thread Peter Otten
ough it could be base 36 or similar). > One input that is a number in return you are getting 6 digit alphanumeric > string. > > I tried this > s = '%06d' % random.randint(0, 99) > > it gives : '192862' (a string ) Your question is not very clear. Can you

Re: random number

2012-03-26 Thread Grzegorz Staniak
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)

Re: random number

2012-03-25 Thread Nikhil Verma
t; > > > On Mon, Mar 26, 2012 at 2:08 AM, Nikhil Verma wrote: > >> Hi All >> >> How can we generate a 6 digit random number from a given number ? >> >> eg:- >> >> def number_generator(id): >> random.randint(id,99) >> >>

Re: random number

2012-03-25 Thread Michael Poeltl
* Nikhil Verma [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

Re: random number

2012-03-25 Thread Chris Angelico
On Mon, Mar 26, 2012 at 5:08 PM, Nikhil Verma wrote: > Hi All > > How can we generate a 6 digit random number from a given number ? > > eg:- > > def number_generator(id): >     random.randint(id,99) > > When i am using this it is sometimes giving me five digit

Re: random number

2012-03-25 Thread Daniel da Silva
If you want it as an int: random.randint(10, 99) Or as a string: s = '%06d' % random.randint(0, 99) On Mon, Mar 26, 2012 at 2:08 AM, Nikhil Verma wrote: > Hi All > > How can we generate a 6 digit random number from a given number ? > > eg:- &g

random number

2012-03-25 Thread Nikhil Verma
Hi All How can we generate a 6 digit random number from a given number ? eg:- def number_generator(id): random.randint(id,99) When i am using this it is sometimes giving me five digit and sometimes 6 . I want to avoid encryption . Can i have alphanumeric 6 digit random number from this

Re: Weibull distr. random number generation

2010-11-22 Thread Dimos
Hello Mark, Exactly, thanks very much! Dimos --- On Sat, 11/20/10, Mark Dickinson wrote: > From: Mark Dickinson > Subject: Re: Weibull distr. random number generation > To: python-list@python.org > Date: Saturday, November 20, 2010, 7:09 PM > On Nov 19, 3:21 pm, Dimos >

Re: Weibull distr. random number generation

2010-11-20 Thread Mark Dickinson
On Nov 19, 3:21 pm, Dimos wrote: > I would like to use the random module, and if I understand well the Random > class, to create  1300 decimal numbers in python, by providing the 2 Weibull > parameters (b,c). How this can be done??? > > import random > print random > random.weibullvariate(b,c) >

Weibull distr. random number generation

2010-11-20 Thread Dimos
Dear Python list subscribers, Sorry of this has been covered already...This is a newbie question about actual scripting/syntax. I would like to use the random module, and if I understand well the Random class, to create 1300 decimal numbers in python, by providing the 2 Weibull parameters (b,

Re: random number generation

2010-08-16 Thread Raymond Hettinger
On Aug 16, 5:37 pm, Jah_Alarm wrote: > hi, > > I need to generate a binary array with a specified average proportion > of 1s (e.g. [1 0 0 0 > > 0 1 0 0] has this proportion = 25%). In Matlab I run something like > random(m,n) > between 0 and 1. I'm trying to use random.randint(0,2,size=[m,n]), but

Re: random number generation

2010-08-16 Thread Brian Blais
On Aug 16, 2010, at 20:37 , Jah_Alarm wrote: hi, I need to generate a binary array with a specified average proportion of 1s (e.g. [1 0 0 0 0 1 0 0] has this proportion = 25%). In Matlab I run something like random(m,n) if you're coming from matlab, then you should use the numpy package (an

random number generation

2010-08-16 Thread Jah_Alarm
hi, I need to generate a binary array with a specified average proportion of 1s (e.g. [1 0 0 0 0 1 0 0] has this proportion = 25%). In Matlab I run something like random(m,n)http://mail.python.org/mailman/listinfo/python-list

Re: Instatiable Pseudo-Random Number Generator

2009-09-10 Thread Hans Georg Schaathun
On Thu, 10 Sep 2009 02:53:33 -0700 (PDT), sturlamolden wrote: : On 10 Sep, 10:50, Hans Georg Schaathun wrote: : : > Can anyone recommend a PRNG which supported multiple instances : > with independent states, and that also can return numpy.array (or : > something similar) efficiently? : : nu

Re: Instatiable Pseudo-Random Number Generator

2009-09-10 Thread Joachim Strömbergson
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Aloha! Hans Georg Schaathun wrote: > Can anyone recommend a PRNG which supported multiple instances > with independent states, and that also can return numpy.array (or > something similar) efficiently? > > The distribution is currently Gaussian. Do

Re: Instatiable Pseudo-Random Number Generator

2009-09-10 Thread sturlamolden
On 10 Sep, 10:50, Hans Georg Schaathun wrote: > Can anyone recommend a PRNG which supported multiple instances > with independent states, and that also can return numpy.array (or > something similar) efficiently? numpy.random.RandomState ;-) S.M. -- http://mail.python.org/mailman/listinfo/pyt

Re: Instatiable Pseudo-Random Number Generator

2009-09-10 Thread Vlastimil Brom
help text : """ Help on built-in function rand in module gmpy: rand(...) rand(opt[,arg]): expose various GMP random-number operations, depending on value of parameter 'opt' (a string) -- arg is normally an int or mpz (or else gets coerced to mpz), but

Instatiable Pseudo-Random Number Generator

2009-09-10 Thread Hans Georg Schaathun
I wonder if someone knows of an API with the features I need... random.Random and numpy.random each have only half of it... My application includes an object to hold a pseudo-randomly generated matrix too large to be kept in memory. Hence I try to store only the seed, and generate the numbers on

Re: random number including 1 - i.e. [0,1]

2009-06-14 Thread Lawrence D'Oliveiro
In message , Esmail wrote: > Here is part of the specification of an algorithm I'm implementing that > shows the reason for my original query: > > vid = w * vid + c1 * rand( ) * ( pid – xid ) + c2 * Rand( ) * (pgd –xid ) (1a) > > xid = xid + vid (1b) Are the terms meant to be clamped to a parti

Re: random number including 1 - i.e. [0,1]

2009-06-14 Thread Lawrence D'Oliveiro
In message , Esmail wrote: > I'm implementing a Particle Swarm Optimizer. Depending on what paper you > read you'll see mention of required random values "between 0 and 1" > which is somewhat ambiguous. I came across one paper that specified > the range [0,1], so inclusive 1, which was the reason

Re: random number including 1 - i.e. [0,1]

2009-06-14 Thread Lawrence D'Oliveiro
In message , Jussi Piitulainen wrote: > Miles Kaufmann writes: > >> I'm curious what algorithm calls for random numbers on a closed >> interval. > > The Box-Muller transform, polar form. At least Wikipedia says so. Doesn't seem to be necessary, if I interpret the following correctly

Re: random number including 1 - i.e. [0,1]

2009-06-11 Thread Esmail
Thanks everyone, I learned more than I expected about floats :-) and got some good explanations and ideas about all of this. Esmail -- http://mail.python.org/mailman/listinfo/python-list

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Steven D'Aprano
not* obvious even for people who are aware that floats do funny things. I know I got caught out by it. However, rather than a documentation patch, I'd prefer to see uniform() fixed to return a value in the half-open interval. Something like: def uniform(self, a, b): &qu

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Robert Kern
On 2009-06-10 16:47, Mark Dickinson wrote: And of course I'm wrong. I shouldn't have said *never*, above: from random import uniform uniform(-1e308, 1e308) inf :-( Somehow this doesn't seem worth either fixing or documenting, though. Agreed. -- Robert Kern "I have come to believe that

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Mark Dickinson
Robert Kern wrote: > On 2009-06-10 15:54, Mark Dickinson wrote: >> [...] I'm not sure I'm capable of coming up with extra wording >> for the docs that won't just cause more confusion, so I'll leave that >> to someone else. > > I did make a concrete suggestion. Yes, you did. Thank you. Submitte

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Carl Banks
On Jun 9, 2:33 pm, Esmail wrote: > Hi, > > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? > > I am implementing an algorithm and want to stay as true to the > original design specificati

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Robert Kern
On 2009-06-10 15:54, Mark Dickinson wrote: Robert Kern wrote: On 2009-06-10 14:46, Mark Dickinson wrote: On Jun 10, 8:15 pm, Robert Kern wrote: On 2009-06-10 13:53, Terry Reedy wrote: A full technical discussion does not below in the docs, in my opinion. A wike article would be fine. True

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Mark Dickinson
Robert Kern wrote: > On 2009-06-10 14:46, Mark Dickinson wrote: >> On Jun 10, 8:15 pm, Robert Kern wrote: >>> On 2009-06-10 13:53, Terry Reedy wrote: A full technical discussion does not below in the docs, in my opinion. A wike article would be fine. >>> True. However, a brief note that

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Robert Kern
On 2009-06-10 15:32, Robert Kern wrote: On 2009-06-10 14:46, Mark Dickinson wrote: But I don't know why it would be useful to know that endpoints *are* sometimes included, without knowing exactly when. That's a fair point. However, one issue that hasn't been brought up is that it might be co

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Robert Kern
On 2009-06-10 14:46, Mark Dickinson wrote: On Jun 10, 8:15 pm, Robert Kern wrote: On 2009-06-10 13:53, Terry Reedy wrote: A full technical discussion does not below in the docs, in my opinion. A wike article would be fine. True. However, a brief note that "Due to floating point arithmetic, fo

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Mark Dickinson
On Jun 10, 8:15 pm, Robert Kern wrote: > On 2009-06-10 13:53, Terry Reedy wrote: > > A full technical discussion does not below in the docs, in my opinion. A > > wike article would be fine. > > True. However, a brief note that "Due to floating point arithmetic, for some > values of a and b, b may

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Robert Kern
But docs say that in general end point values might happen. They do not say that in every particular case, they will happen. I'm not so sure. Context is important. When discussing the bounds of random number generators, specifying <= instead of < strongly suggests that the bound is

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Mark Dickinson
On Jun 10, 6:57 pm, Mensanator wrote: > On Jun 10, 12:37 pm, Mark Dickinson wrote: > > > On Jun 10, 6:21 pm, Mensanator wrote: > > > > So, the 2.6.2 documentation is STILL wrong. Before it implied > > > it was ALWAYS a semi-open interval, and now it says it's ALWAYS > > > a closed interval. But

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Terry Reedy
Mensanator wrote: So, the 2.6.2 documentation is STILL wrong. Before it implied it was ALWAYS a semi-open interval, and now it says it's ALWAYS a closed interval. But neither is correct. If a < x < b is true, then a <= x <= b is true. But docs say that in general end point values might happen.

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Robert Kern
On 2009-06-09 19:27, Mensanator wrote: On Jun 9, 6:12 pm, Robert Kern wrote: On 2009-06-09 18:05, Mensanator wrote: On Jun 9, 4:33 pm, Esmailwrote: Hi, random.random() will generate a random value in the range [0, 1). Is there an easy way to generate random values in the range [0, 1]

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Mensanator
On Jun 10, 12:37 pm, Mark Dickinson wrote: > On Jun 10, 6:21 pm, Mensanator wrote: > > > So, the 2.6.2 documentation is STILL wrong. Before it implied > > it was ALWAYS a semi-open interval, and now it says it's ALWAYS > > a closed interval. But neither is correct. > > Exactly which bit of the 2.

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Mark Dickinson
On Jun 10, 6:21 pm, Mensanator wrote: > So, the 2.6.2 documentation is STILL wrong. Before it implied > it was ALWAYS a semi-open interval, and now it says it's ALWAYS > a closed interval. But neither is correct. Exactly which bit of the 2.6.2 documentation do you think is incorrect? The documen

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Mensanator
On Jun 10, 4:01 am, Mark Dickinson wrote: > On Jun 10, 7:25 am, John Yeung wrote: > > > > > > > On Jun 10, 1:52 am, Steven D'Aprano > > > wrote: > > > On Tue, 09 Jun 2009 22:21:26 -0700, John Yeung wrote: > > > > Therefore, to me the most up-to-date docs (which say > > > > that uniform(a, b) ret

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Paul McGuire
On Jun 9, 11:23 pm, Esmail wrote: > Here is part of the specification of an algorithm I'm implementing that > shows the reason for my original query: > > vid = w * vid + c1 * rand( ) * ( pid – xid ) + c2 * Rand( ) * (pgd –xid ) (1a) > > xid = xid + vid (1b) > > where c1 and c2 are two positive con

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread dickinsm
Esmail wrote: > Hi, > > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? > > [...] Here are three recipes, each more pedantic than the last. They all assume that Python floats are IEE

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Mark Dickinson
On Jun 10, 7:25 am, John Yeung wrote: > On Jun 10, 1:52 am, Steven D'Aprano > > wrote: > > On Tue, 09 Jun 2009 22:21:26 -0700, John Yeung wrote: > > > Therefore, to me the most up-to-date docs (which say > > > that uniform(a, b) returns a float in the closed > > > interval [a, b]) is closer to co

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Jussi Piitulainen
Esmail writes: > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? > > I am implementing an algorithm and want to stay as true to the > original design specifications as possible though I

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Andre Engels
On Wed, Jun 10, 2009 at 8:25 AM, John Yeung wrote: > That uniform(a, b) will return a random float in the semi-open > interval [a, b) for certain values of a and b; and in the closed > interval [a, b] for other values of a and b.  (Swap a and b if a > b.) > > To me, the fact that you sometimes get

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread alex23
On Jun 10, 3:24 pm, John Yeung wrote: > Alex, did you bother to read what I quoted?  Paul McGuire suggested an > alternative in case the OP was choosing integers in a roundabout way. > I was merely pointing out that Paul's solution can be more simply > achieved using a library function. My apolog

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Lorenzo Gatti
On 10 Giu, 06:23, Esmail wrote: > Here is part of the specification of an algorithm I'm implementing that > shows the reason for my original query: > > vid = w * vid + c1 * rand( ) * ( pid – xid ) + c2 * Rand( ) * (pgd –xid ) (1a) > > xid = xid + vid (1b) > > where c1 and c2 are two positive const

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Jussi Piitulainen
Miles Kaufmann writes: [...] > I'm curious what algorithm calls for random numbers on a closed > interval. The Box-Muller transform, polar form. At least Wikipedia says so. -- http://mail.python.org/mailman/listinfo/python-list

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Virgil Stokes
ation in C is both fast and threadsafe. The Mersenne Twister is one of the most extensively tested random number generators in existence. However, being completely deterministic, it is not suitable for all purposes, and is completely unsuitable for cryptographic purposes. The notation above means

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread John Yeung
On Jun 10, 1:52 am, Steven D'Aprano wrote: > On Tue, 09 Jun 2009 22:21:26 -0700, John Yeung wrote: > > Therefore, to me the most up-to-date docs (which say > > that uniform(a, b) returns a float in the closed > > interval [a, b]) is closer to correct than before, > > but still fails to point out t

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Mensanator
; > abandon Python and run out and buy Mathematica. > > > Look at how the change of random to the Mersenne Twister was handled. > > That's what we, the users, want to see. > > Speak for yourself. What about the change that you think "we, the users", > w

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Dave Angel
Steven D'Aprano wrote: On Tue, 09 Jun 2009 18:28:23 -0700, John Yeung wrote: The docs are now... sort of correct. For some values of a and b, uniform() can never return b. Notably, I believe uniform(0, 1) is equivalent to random(), and will never return 1. However, uniform(1, 2) CAN retur

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Steven D'Aprano
On Tue, 09 Jun 2009 22:21:26 -0700, John Yeung wrote: > On Jun 9, 11:24 pm, Steven D'Aprano > wrote: >> On Tue, 09 Jun 2009 18:28:23 -0700, John Yeung wrote: >> > The docs are now... sort of correct.  For some values of a and b, >> > uniform() can never return b.  Notably, I believe uniform(0, 1)

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread John Yeung
On Jun 10, 12:01 am, alex23 wrote: > On Jun 10, 11:32 am, John Yeung wrote: > > > On Jun 9, 8:39 pm, Paul McGuire wrote: > > > Are you trying to generate a number in the > > > range [0,n] by multiplying a random function that > > > returns [0,1] * n?  If so, then you want to do > > > this using:

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread John Yeung
On Jun 9, 11:24 pm, Steven D'Aprano wrote: > On Tue, 09 Jun 2009 18:28:23 -0700, John Yeung wrote: > > The docs are now... sort of correct.  For some values of a and b, > > uniform() can never return b.  Notably, I believe uniform(0, 1) is > > equivalent to random(), and will never return 1.  Howe

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Steven D'Aprano
On Tue, 09 Jun 2009 21:04:49 -0700, Mensanator wrote: > On Jun 9, 8:28�pm, John Yeung wrote: >> On Jun 9, 8:45�pm, Mensanator wrote: >> >> > On Jun 9, 6:05�pm, "Gabriel Genellina" >> > wrote: >> > > py> a+(b-a)*z < b # the expression used for uniform(a,b) False >> > > py> a+(b-a)*z >> > > 11.0

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Esmail
Here is part of the specification of an algorithm I'm implementing that shows the reason for my original query: vid = w * vid + c1 * rand( ) * ( pid – xid ) + c2 * Rand( ) * (pgd –xid ) (1a) xid = xid + vid (1b) where c1 and c2 are two positive constants, rand() and Rand() are two random functi

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread AggieDan04
On Jun 9, 4:33 pm, Esmail wrote: > Hi, > > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? You could do random.uniform(0, 1.0002). Due to floating- point rounding, there are

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Mensanator
On Jun 9, 8:28�pm, John Yeung wrote: > On Jun 9, 8:45�pm, Mensanator wrote: > > > On Jun 9, 6:05�pm, "Gabriel Genellina" wrote: > > > py> a+(b-a)*z < b # the expression used for uniform(a,b) > > > False > > > py> a+(b-a)*z > > > 11.0 > > > What you do with the number after it's created is not >

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread alex23
On Jun 10, 11:32 am, John Yeung wrote: > On Jun 9, 8:39 pm, Paul McGuire wrote: > > Are you trying to generate a number in the > > range [0,n] by multiplying a random function that > > returns [0,1] * n?  If so, then you want to do > > this using: int(random.random()*(n+1))  This will > > give eq

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Steven D'Aprano
On Tue, 09 Jun 2009 18:28:23 -0700, John Yeung wrote: > The docs are now... sort of correct. For some values of a and b, > uniform() can never return b. Notably, I believe uniform(0, 1) is > equivalent to random(), and will never return 1. However, uniform(1, 2) > CAN return 2, if this is any i

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread John Yeung
On Jun 9, 8:39 pm, Paul McGuire wrote: > Are you trying to generate a number in the > range [0,n] by multiplying a random function that > returns [0,1] * n?  If so, then you want to do > this using: int(random.random()*(n+1))  This will > give equal chance of getting any number from 0 to n. Bette

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread John Yeung
On Jun 9, 8:45 pm, Mensanator wrote: > On Jun 9, 6:05 pm, "Gabriel Genellina" wrote: > > py> a+(b-a)*z < b # the expression used for uniform(a,b) > > False > > py> a+(b-a)*z > > 11.0 > > What you do with the number after it's created is not > random's concern. Mensanator, you missed Gabriel's po

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Mensanator
On Jun 9, 6:05 pm, "Gabriel Genellina" wrote: > En Tue, 09 Jun 2009 18:33:39 -0300, Esmail escribió: > > > random.random() will generate a random value in the range [0, 1). > > > Is there an easy way to generate random values in the range [0, 1]? > > I.e., including 1? > > I think you shouldn't w

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Paul McGuire
bability of getting 0 or n as any other value. If you want to perform a fair roll of a 6-sided die, you would start with int(random.random() * 6). This gives a random number in the range [0,5], with each value of the same probability. How to get our die roll that goes from 1 to 6? Add 1. Thus:

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Mensanator
On Jun 9, 6:12 pm, Robert Kern wrote: > On 2009-06-09 18:05, Mensanator wrote: > > > > > > > On Jun 9, 4:33 pm, Esmail  wrote: > >> Hi, > > >> random.random() will generate a random value in the range [0, 1). > > >> Is there an easy way to generate random values in the range [0, 1]? > >> I.e., inc

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Esmail
Miles Kaufmann wrote: I'm curious what algorithm calls for random numbers on a closed interval. I'm implementing a Particle Swarm Optimizer. Depending on what paper you read you'll see mention of required random values "between 0 and 1" which is somewhat ambiguous. I came across one paper that

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Esmail
Robert Kern wrote: On 2009-06-09 18:05, Mensanator wrote: On Jun 9, 4:33 pm, Esmail wrote: That's wrong. Where did you get it? http://docs.python.org/library/random What he said :-) (thanks Robert) -- http://mail.python.org/mailman/listinfo/python-list

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Esmail
Gabriel Genellina wrote: En Tue, 09 Jun 2009 18:33:39 -0300, Esmail escribió: random.random() will generate a random value in the range [0, 1). Is there an easy way to generate random values in the range [0, 1]? I.e., including 1? I think you shouldn't worry about that - the difference may

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Miles Kaufmann
On Jun 9, 2009, at 7:05 PM, Mensanator wrote: On Jun 9, 4:33 pm, Esmail wrote: Hi, random.random() will generate a random value in the range [0, 1). Is there an easy way to generate random values in the range [0, 1]? I.e., including 1? I am implementing an algorithm and want to stay as true

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Robert Kern
On 2009-06-09 18:05, Mensanator wrote: On Jun 9, 4:33 pm, Esmail wrote: Hi, random.random() will generate a random value in the range [0, 1). Is there an easy way to generate random values in the range [0, 1]? I.e., including 1? I am implementing an algorithm and want to stay as true to the

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Mensanator
ch that a <= N <= b for a <= b That's wrong. Where did you get it? >>> help(random.uniform) Help on method uniform in module random: uniform(self, a, b) method of random.Random instance Get a random number in the range [a, b). > > this seems to imply an inclusive

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Gabriel Genellina
En Tue, 09 Jun 2009 18:33:39 -0300, Esmail escribió: random.random() will generate a random value in the range [0, 1). Is there an easy way to generate random values in the range [0, 1]? I.e., including 1? I think you shouldn't worry about that - the difference may be as small as 2**-53, o

random number including 1 - i.e. [0,1]

2009-06-09 Thread Esmail
ict it: In [3]: random.uniform? Type: instancemethod Base Class: String Form:> Namespace: Interactive File: /usr/lib/python2.6/random.py Definition: random.uniform(self, a, b) Docstring: Get a random number in the range [a, b). -- http://mail.python.org

True random number generator

2008-05-24 Thread Zerge
truerandom.py is a Python module that generates true random numbers obtained from www.random.org. Use with the form: mylist=truerandom.getnum(min,max,amount) mylist will be a list containing the true random numbers. If for some reason the numbers cannot be generated, the list will contain -1. Y

making pseudo random number with spam ad convert text to binary

2006-07-29 Thread bussiere maillist
here is a little project to make a more or less good pseudo random generator by using spam :http://euryale.googlecode.com/it's almost quite finished but i've got a last problem i didn't manage to convert text to binary : hazard = binascii.a2b_qp(attachment) + binascii.a2b_qp(body) + binascii.a2b_qp

Re: Random Number Generator Error

2006-03-18 Thread Fredrik Lundh
"ahmet nurlu" wrote: > It gives error: > Traceback (most recent call last): >File "random.py", line 2, in ? > from pylab import * >File "/usr/lib/python2.4/site-packages/pylab.py", line 1, in ? > from matplotlib.pylab import * >File "/usr/lib/python2.4/site-packages/mat

Random Number Generator Error

2006-03-18 Thread ahmet nurlu
Hi, I wrote a random walk program which you will find below.  When I run it from the terminal, it gives error which I am not able to figure out what could be wrong. From the bash shell, I give a command     >python2.4 random.py It gives error: --

Re: What random number generator is used for Numeric and SciPy?

2005-12-18 Thread Robert Kern
The Helmbolds wrote: > > Python bases its random number generators on the Mersenne Twister. > > Do Numeric and SciPy also base their random number generators on the > Mersenne Twister? If not, what do they use? Numeric, numarray and scipy 0.3 use RANLIB. http://www.stat.umn.

What random number generator is used for Numeric and SciPy?

2005-12-18 Thread The Helmbolds
Python bases its random number generators on the Mersenne Twister.   Do Numeric and SciPy also base their random number generators on the Mersenne Twister? If not, what do they use?-- http://mail.python.org/mailman/listinfo/python-list

Re: Random Number Generation?

2005-12-11 Thread Mike Meyer
[EMAIL PROTECTED] (Bengt Richter) writes: > Theoretically, the chances of getting an integer from a uniformly > random sample from an interval of real numbers is practically zero, > and even allowing for IEEE 754 double representation, Well, if we're going to be picky, the chances of getting a num

Re: Random Number Generation?

2005-12-11 Thread Bengt Richter
On Sun, 11 Dec 2005 09:46:33 -0800 (PST), Dimos <[EMAIL PROTECTED]> wrote: >Hello All, > >I need some help with random number generation. What I >need exactly is: > >To create a few thousand numbers, decimal and >integers, between 5 and 90, >and then to expor

  1   2   >