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 is there a

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 pick numbe

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 certain numbers, is this possible? > > > > random.randint

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? > > > > random.randint(1,100) work

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 and > 100 but say i do

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 want 48 to come

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

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
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. On Mon, Mar 26, 2012 at 2:54 PM, Michael Poeltl wrote:

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(''.join(

Re: random number

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

Re: random number

2012-03-26 Thread Peter Otten
Nikhil Verma wrote: > 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 That's normally not called a number (though it could be base 36 or similar). > One

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)) >> ... random.shuffle(s) >> ... return int(''.join(s)) >> ... > pr

Re: random number

2012-03-25 Thread Nikhil Verma
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.randi

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(''.join(s)) ... >>> print (rand_given_nu

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 and sometimes 6 . > I want to avo

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:- > > def number_generator(id): > rando

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

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
On Wed, 10 Jun 2009 15:32:05 -0500, Robert Kern wrote: > That's a fair point. However, one issue that hasn't been brought up is > that it might be confusing to a user why random.random() returns values > in a half-open interval while random.uniform() claims a closed interval. > Even for reasonably

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
On 2009-06-10 13:53, Terry Reedy wrote: 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

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
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 correct than befor

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
On Jun 9, 11:28�pm, Steven D'Aprano wrote: > 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 fo

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
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? > Are you trying to generate a number in the range [0,n] by multiplying a random function that

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
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 > original design specificati

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

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

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 export them as a single column at a >spread

Re: Random Number Generation?

2005-12-11 Thread [EMAIL PROTECTED]
Dimos 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 export them as a single column at a > spreadsheet. > > I am newbie, I was not able to create decimal

Re: Random Number Generation?

2005-12-11 Thread Fredrik Lundh
Dimos wrote: > 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 export them as a single column at a > spreadsheet. > > I am newbie, I was not able to create decimals with > the ra

Re: Random Number Generation?

2005-12-11 Thread Alex Martelli
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 export them as a single column at a > spreadsheet. > > I am newbie, I was no

Re: random number generator thread safety

2005-11-08 Thread Mike Brown
Raymond Hettinger wrote: > Mike Brown wrote: > > I have questions about thread safety in the 'random' module. > > > > When using the random.Random class (be it Mersenne Twister or Wichmann-Hill > > based), is it sufficiently thread-safe (preserving entropy and guarding > > against attack) to just h

Re: random number generator thread safety

2005-11-08 Thread Raymond Hettinger
> > Thread-safety has nothing to do with preserving entropy or guarding > > against attack. All of the entropy in an MT sequence is contained in > > the seed (upto 624 bytes) and that entropy is preserved through all > > subsequent calls. > > I think the concern is that there can be a thread switc

Re: random number generator thread safety

2005-11-08 Thread Paul Rubin
"Raymond Hettinger" <[EMAIL PROTECTED]> writes: > Thread-safety has nothing to do with preserving entropy or guarding > against attack. All of the entropy in an MT sequence is contained in > the seed (upto 624 bytes) and that entropy is preserved through all > subsequent calls. I think the concer

Re: random number generator thread safety

2005-11-08 Thread Raymond Hettinger
Mike Brown wrote: > I have questions about thread safety in the 'random' module. > > When using the random.Random class (be it Mersenne Twister or Wichmann-Hill > based), is it sufficiently thread-safe (preserving entropy and guarding > against attack) to just have each thread work with its own ran

Re: random number generator

2005-11-04 Thread Bryan Olson
Fredrik Lundh wrote: >>How to generate a random number in Python. Is there any build in >>function I can call? > > > >>> import random > >>> help(random) If you need crypto-quality randomness: >>> import os >>> help(os.urandom) -- --Bryan -- http://mail.python.org/mailman/listinfo

Re: random number generator

2005-11-03 Thread avnit
import random print random.randint(1,20) #prints random integer from 1 to 20 -- http://mail.python.org/mailman/listinfo/python-list

Re: random number generator

2005-11-03 Thread Fredrik Lundh
> How to generate a random number in Python. Is there any build in > function I can call? >>> import random >>> help(random) also see: http://docs.python.org/lib/module-random.html -- http://mail.python.org/mailman/listinfo/python-list

Re: random number between 0 and 20

2005-04-20 Thread TZOTZIOY
On Wed, 20 Apr 2005 11:10:21 -0400, rumours say that Peter Hansen <[EMAIL PROTECTED]> might have written: >NNTP-Posting-Date: Wed, 20 Apr 2005 10:20:45 -0500 >Date: Wed, 20 Apr 2005 11:10:21 -0400 Based on these headers from your message, plus the fact that you answered five minutes before aleksa

Re: random number between 0 and 20

2005-04-20 Thread aleksander . helgaker
Yes I know about assigning and all that. I just stated the name of the variable so that people could easily explain how to create the random number. I needed it to practice Python. I just finished making a number guess program. I just finished it. It was much easier to do then I thought it would be

Re: random number between 0 and 20

2005-04-20 Thread Peter Hansen
[EMAIL PROTECTED] wrote: How can I generate a random number between 0 - 20 and store the number in nrrandom? You would use the "random" module from the standard library. It has a randint() method that should do the job. Read the docs for more. Assigning to nrrandom? Is that just a variable name?

Re: random number between 0 and 20

2005-04-20 Thread Will McGugan
[EMAIL PROTECTED] wrote: How can I generate a random number between 0 - 20 and store the number in nrrandom? Assuming its inclusive.. >>> from random import randint >>> nrrandom = randint(0,20) Will McGugan -- http://www.willmcgugan.com "".join( [ {'*':'@','^':'.'}.get(c,None) or chr(97+(ord(c)-84)

Re: random number between 0 and 20

2005-04-20 Thread TZOTZIOY
On 20 Apr 2005 08:15:02 -0700, rumours say that [EMAIL PROTECTED] might have written: >How can I generate a random number between 0 - 20 and store the number >in nrrandom? Just choose a random number yourself, eg. nrrandom=17 (just kidding :) import random nrrandom = random.randint(0,20) See

Re: Random number generation from functions

2004-11-30 Thread Alejandro López-Valencia
On Mon, 29 Nov 2004 20:51:50 GMT, "drs" <[EMAIL PROTECTED]> wrote: >Is there any way to generate random numbers based on arbitrary real valued >functions? I am looking for something like random.gauss() but with natural >log and exponential functions. Try with CRNG, it may have what you need, or b

Re: Random number generation from functions

2004-11-30 Thread Robert Kern
drs wrote: Is there any way to generate random numbers based on arbitrary real valued functions? I am looking for something like random.gauss() but with natural log and exponential functions. scipy[1] has a large collection of "standard" univariate pdfs, including normal, exponential, gamma, and t

Re: Random number generation from functions

2004-11-29 Thread CptPicard
drs wrote: Is there any way to generate random numbers based on arbitrary real valued functions? I am looking for something like random.gauss() but with natural log and exponential functions. thanks, -d I remember for having used it on a gaussian generator that you can do that very easily by your

Re: Random number generation from functions

2004-11-29 Thread Colin J. Williams
drs wrote: Is there any way to generate random numbers based on arbitrary real valued functions? I am looking for something like random.gauss() but with natural log and exponential functions. thanks, -d numarray has a random package which provides a number of functions, including: normal( mean,

Re: Random number generation from functions

2004-11-29 Thread Bengt Richter
On Mon, 29 Nov 2004 20:51:50 GMT, "drs" <[EMAIL PROTECTED]> wrote: >Is there any way to generate random numbers based on arbitrary real valued >functions? I am looking for something like random.gauss() but with natural >log and exponential functions. > >thanks, Don't know what you mean. This kind