Re: lotto number generator

2015-06-01 Thread Ian Kelly
On Mon, Jun 1, 2015 at 11:13 AM, Ian Kelly wrote: > On Mon, Jun 1, 2015 at 10:23 AM, gm wrote: >> Hi. >> I am new to python so am still in learning phase. >> >> I was thinking to make one program that will print out all possible >> combinations of 10 pairs. I think this is a good way for somethin

Re: lotto number generator

2015-06-01 Thread Ian Kelly
On Mon, Jun 1, 2015 at 10:23 AM, gm wrote: > Hi. > I am new to python so am still in learning phase. > > I was thinking to make one program that will print out all possible > combinations of 10 pairs. I think this is a good way for something "bigger" > :-). > > This is how this looks like: > > 1.)

Re: lotto number generator

2015-06-01 Thread Grant Edwards
On 2015-06-01, gm wrote: > I was thinking to make one program that will print out all possible > combinations of 10 pairs. [...] > What would be the best way to make something like this? > Maybe some tutorial ? https://www.google.com/search?q=python+combinations -- Grant Edwards

lotto number generator

2015-06-01 Thread gm
Hi. I am new to python so am still in learning phase. I was thinking to make one program that will print out all possible combinations of 10 pairs. I think this is a good way for something "bigger" :-). This is how this looks like: 1.) 1 2 2.) 1 2 3.) 1 2 4.) 1 2 5.) 1 2 6.) 1 2 7.) 1 2 8.)

Re: Prime number generator

2013-07-31 Thread Ian Kelly
On Tue, Jul 30, 2013 at 4:58 AM, Albert van der Horst wrote: > Notice that all values from i on are possibly present. > So you are better off with a list indexed by forthcoming i's and > each item containing a list of primes. What you do then, more or less, > is keep track of all dividers of prime

Re: Prime number generator

2013-07-30 Thread bryanjugglercryptographer
Chris Angelico wrote: > Bas wrote: > > Still trying to figure out your algorithm ... > > It's pretty simple. (That's a bad start, I know!) Like the Sieve of > Eratosthenes, it locates prime numbers, then deems every multiple of > them to be composite. Unlike the classic sieve, it does the "deem" >

Re: Prime number generator

2013-07-30 Thread Albert van der Horst
In article , Chris Angelico wrote: >And now for something completely different. > >I knocked together a prime number generator, just for the fun of it, >that works like a Sieve of Eratosthenes but unbounded. It keeps track >of all known primes and the "next composite" th

Re: Prime number generator

2013-07-10 Thread Joshua Landau
On 10 July 2013 19:56, Ian Kelly wrote: > On Wed, Jul 10, 2013 at 11:47 AM, Joshua Landau wrote: If you care about speed, you might want to check the heapq module. Removing the smallest item and inserting a new item in a heap both cost O(log(N)) time, while finding the minimum in

Re: Prime number generator

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 11:47 AM, Joshua Landau wrote: >>> If you care about speed, you might want to check the heapq module. Removing >>> the smallest item and inserting a new item in a heap both cost O(log(N)) >>> time, while finding the minimum in a dictionary requires iterating over the >>>

Re: Prime number generator

2013-07-10 Thread Joshua Landau
On 10 July 2013 17:15, Chris Angelico wrote: > On Thu, Jul 11, 2013 at 1:47 AM, bas wrote: >> On Wednesday, July 10, 2013 5:12:19 PM UTC+2, Chris Angelico wrote: >>> Well, that does answer the question. Unfortunately the use of lambda >>> there has a severe performance cost [ ...] >> If you care

Re: Prime number generator

2013-07-10 Thread Chris Angelico
On Thu, Jul 11, 2013 at 2:54 AM, Ian Kelly wrote: > As promised. Apologies for the excessive commenting. As noted, this > implementation is a recursive generator, which is done so that the > primes in the sieve can go only up to the square root of the current > prime, rather than tossing in ever

Re: Prime number generator

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 10:16 AM, Ian Kelly wrote: > The other interesting thing about my sieve is that it's a recursive > generator. I'll dig it up later and share it. As promised. Apologies for the excessive commenting. As noted, this implementation is a recursive generator, which is done so

Re: Prime number generator

2013-07-10 Thread Chris Angelico
On Thu, Jul 11, 2013 at 2:01 AM, Steven D'Aprano wrote: > On Thu, 11 Jul 2013 00:00:59 +1000, Chris Angelico wrote: >> Thirdly, is there any sort of half-sane benchmark that I >> can compare this code to? And finally, whose wheel did I reinvent here? >> What name would this algorithm have? > > I c

Re: Prime number generator

2013-07-10 Thread Chris Angelico
On Thu, Jul 11, 2013 at 1:47 AM, bas wrote: > On Wednesday, July 10, 2013 5:12:19 PM UTC+2, Chris Angelico wrote: >> Well, that does answer the question. Unfortunately the use of lambda >> there has a severe performance cost [ ...] > If you care about speed, you might want to check the heapq modul

Re: Prime number generator

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 8:00 AM, Chris Angelico wrote: > And now for something completely different. > > I knocked together a prime number generator, just for the fun of it, > that works like a Sieve of Eratosthenes but unbounded. It keeps track > of all known primes and the "

Re: Prime number generator

2013-07-10 Thread Steven D'Aprano
On Thu, 11 Jul 2013 00:00:59 +1000, Chris Angelico wrote: > And now for something completely different. > > I knocked together a prime number generator, just for the fun of it, > that works like a Sieve of Eratosthenes but unbounded. [...] > So, a few questions. Firstly, is there

Re: Prime number generator

2013-07-10 Thread Chris Angelico
On Thu, Jul 11, 2013 at 1:43 AM, Joshua Landau wrote: >> So, a few questions. Firstly, is there... > Of course there is. > >> Secondly, can the... > Of course it can. > >> Thirdly, is there... > Of course there is. I have no clue what, though. Heh, I guess I was asking for that kind of response :

Re: Prime number generator

2013-07-10 Thread bas
On Wednesday, July 10, 2013 5:12:19 PM UTC+2, Chris Angelico wrote: > Well, that does answer the question. Unfortunately the use of lambda > there has a severe performance cost [ ...] If you care about speed, you might want to check the heapq module. Removing the smallest item and inserting a new

Re: Prime number generator

2013-07-10 Thread Joshua Landau
On 10 July 2013 15:00, Chris Angelico wrote: > And now for something completely different. > > I knocked together a prime number generator, just for the fun of it, > that works like a Sieve of Eratosthenes but unbounded. It keeps track > of all known primes and the "next com

Re: Prime number generator

2013-07-10 Thread Chris Angelico
On Thu, Jul 11, 2013 at 12:35 AM, Bas wrote: > On Wednesday, July 10, 2013 4:00:59 PM UTC+2, Chris Angelico wrote: > [...] >> So, a few questions. Firstly, is there a stdlib way to find the key >> with the lowest corresponding value? In the above map, it would return >> 3, because 18 is the lowest

Re: Prime number generator

2013-07-10 Thread Bas
On Wednesday, July 10, 2013 4:00:59 PM UTC+2, Chris Angelico wrote: [...] > So, a few questions. Firstly, is there a stdlib way to find the key > with the lowest corresponding value? In the above map, it would return > 3, because 18 is the lowest value in the list. I want to do this with > a single

Prime number generator

2013-07-10 Thread Chris Angelico
And now for something completely different. I knocked together a prime number generator, just for the fun of it, that works like a Sieve of Eratosthenes but unbounded. It keeps track of all known primes and the "next composite" that it will produce - for instance, after yielding 13, the

Re: Infinite prime number generator

2010-06-29 Thread Thomas Mlynarczyk
Thomas Jollans schrieb: def primes(): yield 1 1 is not a prime number. Greetings, Thomas -- Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison! (Coluche) -- http://mail.python.org/mailman/listinfo/python-list

Re: Infinite prime number generator

2010-06-29 Thread John Posner
On 6/29/2010 12:51 PM, Thomas Jollans wrote: def rprimes(): def elim_mult(n): yield n for p in filter((lambda x:x%n != 0), elim_mult(n+1)): yield p yield 1 for p in elim_mult(2): yield p Thomas, take a look at the thread "Generators/iterators, Pythonicity, an

Infinite prime number generator

2010-06-29 Thread Thomas Jollans
I've been toying with Haskell a bit, and after implementing (essentially) the Sieve of Eratosthenes as an infinite list, thus: primes = 1 : foldr elim_mult [] [2..] where elim_mult n l = n : filter ((/=0) . (`mod` n)) l I wondered how easy it would be to do the same thing in Python. Obviously

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
2009/9/10 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

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

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

Re: number generator

2007-03-14 Thread Anton Vredegoor
Anton Vredegoor wrote: > def memoize(fn): > cache = {} > def proxy(*args): > try: return cache[args] > except KeyError: return cache.setdefault(args, fn(*args)) > return proxy Sorry this doesn't work in this case. This works: def memoize(fn): cache = {

Re: number generator

2007-03-14 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > >>> list(_partitions(25, 24)) > [(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2)] > >>> list(_partitions(25, 25)) > [] Hmm. I'll look into this later if I get a chance. Thanks. -- http://mail.python.org/mailman/listinfo/pyth

Re: number generator

2007-03-14 Thread Anton Vredegoor
Paul Rubin wrote: >> def genpool(n, m): >> if n == 1: >> yield [m] >> else: >> for i in xrange(1, m): >> for rest in genpool(n-1, m-i): >> yield rest + [i] >> >> import random >> print random.choice(list(genpool(n=4, m=20))) > > This generates a

Re: number generator

2007-03-14 Thread Paul Rubin
"Raymond Hettinger" <[EMAIL PROTECTED]> writes: > Since people are posting their solutions now (originally only hints > were provided for the homework problem), here's mine: > > def genpool(n, m): > if n == 1: > yield [m] > else: > for i in xrange(1, m): > for r

Re: number generator

2007-03-14 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > If you generate all the possible sets of five numbers between 1 and 50, > there are 50**5 of them, not 2611. Yes, the idea is generate only the sets that add up to 50. > unique_partitions(60, 6) takes 0.8 seconds; unique_partitions(80, 8) > takes abou

Re: number generator

2007-03-14 Thread Shane Geiger
Raymond: It looks to me as if you are trying to turn a generator into a list in the final line. That doesn't work. Raymond Hettinger wrote: To make the solutions equi-probable, a simple approach is to recursively enumerate all possibilities and then choose one of them with random.choice().

Re: number generator

2007-03-14 Thread Duncan Smith
ratio will be 1. >> > > I was thinking about the same random number generator being used in the two > disparate ways. > > - Hendrik > The code I posted for multinomial variates repeatedly generates independent Poissons until the total is less than, or equal to, the d

Re: number generator

2007-03-14 Thread Alex Martelli
Raymond Hettinger <[EMAIL PROTECTED]> wrote: > [Alex Martelli] > > map([random.randrange(5) for i in xrange(45)].count, xrange(5)) > > > > i.e., this gives 5 integers (each between 0 and 45 included) summing to > > 45 -- add 1 to each of them to get the desired result. > > This is a really nice

Re: number generator

2007-03-14 Thread Duncan Smith
Duncan Smith wrote: > greg wrote: > >>Gabriel Genellina wrote: >> >> >>>The 5th number is not "random". >> >> >>More precisely, the fifth number is not *independent* >>of the others. You can't have five independent random >>numbers that sum to 50; only four independent numbers >>plus a dependent o

Re: number generator

2007-03-14 Thread cesco
> Since people are posting their solutions now (originally only hints > were provided for the homework problem), here's mine: Well, I never really said it was a homework problem. Sure there are more implications to my question that I had first imagined and I'm really happy I could get so many insi

Re: number generator

2007-03-14 Thread Anton Vredegoor
Raymond Hettinger wrote: > Since people are posting their solutions now (originally only hints > were provided for the homework problem), here's mine: Homework problem? Do you have some information from the OP that I can't find in this thread? Anyway, I consider the 'homework' idea and the asso

Re: number generator

2007-03-14 Thread Raymond Hettinger
[Alex Martelli] > map([random.randrange(5) for i in xrange(45)].count, xrange(5)) > > i.e., this gives 5 integers (each between 0 and 45 included) summing to > 45 -- add 1 to each of them to get the desired result. This is a really nice approach. Besides being fast, it is not too hard to see th

Re: number generator

2007-03-14 Thread Hendrik van Rooyen
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote: > > Consider the distance between each paid of consecutive poles. The sum of > the distances must add up to the distance from the first to the last, and > if there are two fixed poles plus five in between, there are five > distances. No there are six

Re: number generator

2007-03-14 Thread Raymond Hettinger
> To make the solutions equi-probable, a simple approach is to > recursively enumerate all possibilities and then choose one of them > with random.choice(). Since people are posting their solutions now (originally only hints were provided for the homework problem), here's mine: def genpool(n, m):

Re: number generator

2007-03-14 Thread Steven D'Aprano
On Wed, 14 Mar 2007 19:25:46 +1100, Steven D'Aprano wrote: > Now that I've seen your _partition() function, I'm quite impressed. It is > still brute-force, but it avoids generating all 50**5 non-unique lists. By > my count, it only has to throw away 11,294 lists to generate the 2611 > unique lists

Re: number generator

2007-03-14 Thread Steven D'Aprano
On Tue, 13 Mar 2007 23:08:38 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> > It should be possible to enumerate all sets of five numbers which sum >> > to 50 and randomly select one of them. >> >> Of course it's possible. It's also a very inefficient way of doing so. F

Re: number generator

2007-03-14 Thread Hendrik van Rooyen
"Gabriel Genellina" <[EMAIL PROTECTED]> wrote: >You can't have two different sets with four equal numbers - it's not a >very difficult thing, it's impossible to distinguish because they're >identical! >Given 4 numbers in the set, the 5th is uniquely determined. By example: >12, 3, 10, 18 *must* e

Re: number generator

2007-03-14 Thread Hendrik van Rooyen
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote: > Easy-peasey. Just collate the individual numbers from the lists, and graph > their frequencies. You will get quite different distributions. Both are > "random", but in different ways. > 8< code - Thanks - I think too com

Re: number generator

2007-03-14 Thread Hendrik van Rooyen
"Duncan Smith" <[EMAIL PROTECTED]> wrote: > Yes, if the generating processes yield numbers from different > probability mass functions. You could simply look at the likelihood > ratio. Otherwise, the likelihood ratio will be 1. > I was thinking about the same r

Re: number generator

2007-03-13 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > > It should be possible to enumerate all sets of five numbers which sum > > to 50 and randomly select one of them. > > Of course it's possible. It's also a very inefficient way of doing so. For > five numbers between 1 and 50, there are 50**5 = 312,500

Re: number generator

2007-03-13 Thread Steven D'Aprano
On Tue, 13 Mar 2007 20:42:17 -0700, [EMAIL PROTECTED] wrote: > It should be possible to enumerate all sets of five numbers which sum > to 50 and randomly select one of them. Of course it's possible. It's also a very inefficient way of doing so. For five numbers between 1 and 50, there are 50**5 =

Re: number generator

2007-03-13 Thread Paul Rubin
Paul Rubin writes: > # yield all partitions of n having length k, with many duplications > def _partitions(n,k): > if k==0: return > for i in xrange(1,n-k+1): > for p in partitions(n-i, k-1): > yield (i,)+p Bah, I manag

Re: number generator

2007-03-13 Thread [EMAIL PROTECTED]
It should be possible to enumerate all sets of five numbers which sum to 50 and randomly select one of them. Cheers, -T -- http://mail.python.org/mailman/listinfo/python-list

Re: number generator

2007-03-13 Thread Dick Moores
At 06:20 PM 3/13/2007, Paul Rubin wrote: >Dick Moores <[EMAIL PROTECTED]> writes: > > I understand what zip() and random.sample() are doing, and the above > > helps me get inside the fencepost method, but I don't understand WHY > > it works, or how in the world anyone could have devised it. It is >

Re: number generator

2007-03-13 Thread Duncan Smith
greg wrote: > Gabriel Genellina wrote: > >> The 5th number is not "random". > > > More precisely, the fifth number is not *independent* > of the others. You can't have five independent random > numbers that sum to 50; only four independent numbers > plus a dependent one. > > -- > Greg In the

Re: number generator

2007-03-13 Thread Duncan Smith
Hendrik van Rooyen wrote: > "Nick Craig-Wood" <[EMAIL PROTECTED]> wrote: > > >>Paul Rubin wrote: >> >>> The fencepost method still seems to be simplest: >>> >>> t = sorted(random.sample(xrange(1,50), 4)) >>> print [(j-i) for i,j in zip([0]+t, t+[50])] >> >>Mmm, nice. >> >>Here is anothe

Re: number generator

2007-03-13 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > Me too. Although Alex Martelli's algorithm: > > map([random.randrange(5) for i in xrange(45)].count, xrange(5)) > > (each value needs adjusting up by one) really boggles my brain. I'm going > to have to think about that. Heh, that is woefully ineffic

Re: number generator

2007-03-13 Thread Steven D'Aprano
On Tue, 13 Mar 2007 08:20:49 +0200, Hendrik van Rooyen wrote: > Is it possible to devise a test that can distinguish between sets > of: > > - five random numbers that add to 50, and > - four random numbers and a fudge number that add to 50? > > My stats are way too small and rusty to attempt to

Re: number generator

2007-03-13 Thread Paul Rubin
Dick Moores <[EMAIL PROTECTED]> writes: > I understand what zip() and random.sample() are doing, and the above > helps me get inside the fencepost method, but I don't understand WHY > it works, or how in the world anyone could have devised it. It is > truly magical to me! It's Gerald Flanagan's te

Re: number generator

2007-03-13 Thread Steven D'Aprano
On Tue, 13 Mar 2007 17:53:41 -0700, Dick Moores wrote: > At 05:47 PM 3/10/2007, Paul Rubin wrote: > >>The fencepost method still seems to be simplest: >> >> t = sorted(random.sample(xrange(1,50), 4)) >> print [(j-i) for i,j in zip([0]+t, t+[50])] > > = > M

Re: number generator

2007-03-13 Thread Dick Moores
At 05:47 PM 3/10/2007, Paul Rubin wrote: >The fencepost method still seems to be simplest: > > t = sorted(random.sample(xrange(1,50), 4)) > print [(j-i) for i,j in zip([0]+t, t+[50])] = M = 50 N = 4 def sumRndIntRubin(M, N): import random t = sort

Re: number generator

2007-03-13 Thread greg
Gabriel Genellina wrote: > The 5th number is not "random". More precisely, the fifth number is not *independent* of the others. You can't have five independent random numbers that sum to 50; only four independent numbers plus a dependent one. -- Greg -- http://mail.python.org/mailman/listinfo/py

Re: number generator

2007-03-13 Thread Gabriel Genellina
En Tue, 13 Mar 2007 03:20:49 -0300, Hendrik van Rooyen <[EMAIL PROTECTED]> escribió: > Is it possible to devise a test that can distinguish between sets > of: > > - five random numbers that add to 50, and > - four random numbers and a fudge number that add to 50? > > My stats are way too small a

Re: number generator

2007-03-13 Thread Paul Rubin
"Terry Reedy" <[EMAIL PROTECTED]> writes: > P(m,n) has no known exact formula but can be computed > inductively rather easily. The partitions for m and n can be ranked in > lexicographic order from 0 to P(m,n)-1. Given a rank r in that range, one > can calculate the particular partition that

Re: number generator

2007-03-13 Thread Anton Vredegoor
Dick Moores wrote: > Paul Rubin's fencepost method is about 14 times faster than mine for > the same M == 8 and N == 4! :( Actually they looked a bit similar after I had mucked a bit with them :-) But indeed it's slow. > Sorry, I don't understand this. Could you spell it out for me by > rewri

Re: number generator

2007-03-13 Thread Dick Moores
At 06:59 AM 3/13/2007, Anton Vredegoor wrote: >Dick Moores wrote: > > > If the added constraint is instead that the probability of generating > > a given list of length N be the same as that of generating any other > > list of length N, then I believe my function does the job. Of course, > > [1,46,

Re: number generator

2007-03-13 Thread Duncan Booth
Dick Moores <[EMAIL PROTECTED]> wrote: >>On the other hand, making sure that each combination occurs equally >>often (as your example might imply) is doable but still leaves the >>question whether the order of the numbers matters: are [1,46,1,1,1] >>and [1,1,46,1,1] the same or different combinati

Re: number generator

2007-03-13 Thread Anton Vredegoor
Dick Moores wrote: > If the added constraint is instead that the probability of generating > a given list of length N be the same as that of generating any other > list of length N, then I believe my function does the job. Of course, > [1,46,1,1,1] and [1,1,46,1,1], as Python lists, are distinc

Re: number generator

2007-03-13 Thread Dick Moores
At 02:52 AM 3/13/2007, Duncan Booth wrote: >Dick Moores <[EMAIL PROTECTED]> wrote: > > > But let's say there is one more constraint--that for each n of the N > > positive integers, there must be an equal chance for n to be any of > > the integers between 1 and M-N+1, inclusive. Thus for M == 50 and

Re: number generator

2007-03-13 Thread Duncan Booth
Dick Moores <[EMAIL PROTECTED]> wrote: > But let's say there is one more constraint--that for each n of the N > positive integers, there must be an equal chance for n to be any of > the integers between 1 and M-N+1, inclusive. Thus for M == 50 and N >== 5, the generated list of 5 should be as l

Re: number generator

2007-03-12 Thread Dick Moores
At 06:38 AM 3/10/2007, Steven D'Aprano wrote: >On Sat, 10 Mar 2007 02:32:21 -0800, Dick Moores wrote: > > > So why not just repeatedly call a function to generate lists of > > length N of random integers within the appropriate range (the closed > > interval [1,M-N-1]), and return the first list the

Re: number generator

2007-03-12 Thread Hendrik van Rooyen
"Nick Craig-Wood" <[EMAIL PROTECTED]> wrote: > Paul Rubin wrote: > > The fencepost method still seems to be simplest: > > > > t = sorted(random.sample(xrange(1,50), 4)) > > print [(j-i) for i,j in zip([0]+t, t+[50])] > > Mmm, nice. > > Here is another effort which is easier to reas

Re: number generator

2007-03-12 Thread Carsten Haese
On Sat, 2007-03-10 at 22:27 -0500, Terry Reedy wrote: > "Anton Vredegoor" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > | Terry Reedy wrote: > | > | > Partitioning positive count m into n positive counts that sum to m is a > | > standard combinatorial problem at least 300 years o

Re: number generator

2007-03-12 Thread Nick Craig-Wood
Paul Rubin wrote: > The fencepost method still seems to be simplest: > > t = sorted(random.sample(xrange(1,50), 4)) > print [(j-i) for i,j in zip([0]+t, t+[50])] Mmm, nice. Here is another effort which is easier to reason about the distribution produced but not as efficient. def rea

Re: number generator

2007-03-12 Thread Duncan Booth
[EMAIL PROTECTED] (Alex Martelli) wrote: > Without any specification regarding the distributions required for the > "5 random numbers" it's really impossible to say whether these are > better or worse than other proposed solutions. FWIW, I decided it would be fun to see what kind of implementatio

Re: number generator

2007-03-11 Thread Alex Martelli
Army1987 <[EMAIL PROTECTED]> wrote: > "cesco" <[EMAIL PROTECTED]> ha scritto nel messaggio > news:[EMAIL PROTECTED] > >I have to generate a list of N random numbers (integer) whose sum is > > equal to M. If, for example, I have to generate 5 random numbers whose > > sum is 50 a possible solution

Re: number generator

2007-03-11 Thread Army1987
"cesco" <[EMAIL PROTECTED]> ha scritto nel messaggio news:[EMAIL PROTECTED] >I have to generate a list of N random numbers (integer) whose sum is > equal to M. If, for example, I have to generate 5 random numbers whose > sum is 50 a possible solution could be [3, 11, 7, 22, 7]. Is there a > simpl

Re: number generator

2007-03-11 Thread MonkeeSage
On Mar 11, 2:16 am, greg <[EMAIL PROTECTED]> wrote: > MonkeeSage wrote: > > this ... requires that M be evenly divisible by N, > > No, it doesn't -- I never said the numbers had > to be *equal*. Sorry for not being clear. I was refering to my specific implementation of the algorithm, not the gener

Re: number generator

2007-03-10 Thread greg
MonkeeSage wrote: > this ... requires that M be evenly divisible by N, No, it doesn't -- I never said the numbers had to be *equal*. > and only works well with smaller N values, Why? > and selections are limited to numbers in the > 1 to (M/N)+(M/N) range I don't understand what you mean by t

Re: number generator

2007-03-10 Thread MonkeeSage
On Mar 10, 11:26 pm, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > To compare to the "cheat" method, calculate the mean and standard > deviation of this sample, and compare to those from the other method. I belieive you (mainly because I'm too lazy to write the sieve, hehe). ;) Regards, Jordan --

Re: number generator

2007-03-10 Thread Steven D'Aprano
On Sat, 10 Mar 2007 17:19:38 -0800, MonkeeSage wrote: > On Mar 10, 6:47 pm, Paul Rubin wrote: >> The fencepost method still seems to be simplest: >> >> t = sorted(random.sample(xrange(1,50), 4)) >> print [(j-i) for i,j in zip([0]+t, t+[50])] > > Simpler, true, b

Re: number generator

2007-03-10 Thread Steven D'Aprano
On Sat, 10 Mar 2007 16:02:56 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> > By your method, what is the probability of the first number being >> > higher than 30? What is the probability of the fifth number being >> > higher than 30? If these probabilities are unequa

Re: number generator

2007-03-10 Thread shellux
On Mar 9, 10:44 pm, "cesco" <[EMAIL PROTECTED]> wrote: > I have to generate a list of N random numbers (integer) whose sum is > equal to M. If, for example, I have to generate 5 random numbers whose > sum is 50 a possible solution could be [3, 11, 7, 22, 7]. Is there a > simple pattern or function

Re: number generator

2007-03-10 Thread Anton Vredegoor
Terry Reedy wrote: > "Anton Vredegoor" <[EMAIL PROTECTED]> wrote in message > | Yes that was one of my first ideas too. But later on Steven pointed out > | that one can view the problem like this: > | > | 0001100010100 > | > | That would be [3,4,3,1,2] > | > | where the '1' elements are like

Re: number generator

2007-03-10 Thread Terry Reedy
"Anton Vredegoor" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Terry Reedy wrote: | | > Partitioning positive count m into n positive counts that sum to m is a | > standard combinatorial problem at least 300 years old. The number of such | > partitions, P(m,n) has no known exa

Re: number generator

2007-03-10 Thread Paulo da Silva
Paul Rubin escreveu: > Paulo da Silva <[EMAIL PROTECTED]> writes: >> May be this is what you want ... >> I didn't test it enough ... but seems fine. > > That's way too complicated. Think about Gerald Flanagan's description > of the telegraph poles, and how to implement simply. It is a two liner.

Re: number generator

2007-03-10 Thread MonkeeSage
On Mar 10, 6:47 pm, Paul Rubin wrote: > The fencepost method still seems to be simplest: > > t = sorted(random.sample(xrange(1,50), 4)) > print [(j-i) for i,j in zip([0]+t, t+[50])] Simpler, true, but I don't think it gives any better distribution... import rand

Re: number generator

2007-03-10 Thread Paul Rubin
"MonkeeSage" <[EMAIL PROTECTED]> writes: > Taking your comment and running with it...this is pretty much > cheating, and requires that M be evenly divisible by N, and only works > well with smaller N values, and selections are limited to numbers in > the 1 to (M/N)+(M/N) range...but hey; other than

Re: number generator

2007-03-10 Thread MonkeeSage
On Mar 10, 3:16 am, greg <[EMAIL PROTECTED]> wrote: > Another possibility is to generate a list of N non-random > numbers that sum to M, and then adjust them up or down > by random amounts. By performing up/down adjustments in > pairs, you can maintain the sum invariant at each step. > So then it's

Re: number generator

2007-03-10 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > > By your method, what is the probability of the first number being > > higher than 30? What is the probability of the fifth number being > > higher than 30? If these probabilities are unequal, can we really say > > the sequences are random? > > Of c

Re: number generator

2007-03-10 Thread Anton Vredegoor
Anton Vredegoor wrote: > L = [1] * (bins-1) + [0] * (bins-1) replace these lines in the code by: L = [1] * (bins-1) + [0] * (bricks-bins) A. -- http://mail.python.org/mailman/listinfo/python-list

Re: number generator

2007-03-10 Thread Steven D'Aprano
On Sat, 10 Mar 2007 08:29:09 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> Doesn't mean that it isn't random. After all, the first four numbers are >> random, therefore their sum is random. 50 - (something random) is also >> random. > > What does it mean for the first

Re: number generator

2007-03-10 Thread Anton Vredegoor
Terry Reedy wrote: > Partitioning positive count m into n positive counts that sum to m is a > standard combinatorial problem at least 300 years old. The number of such > partitions, P(m,n) has no known exact formula but can be computed > inductively rather easily. The partitions for m and n

Re: number generator

2007-03-10 Thread Terry Reedy
"Anton Vredegoor" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Raymond Hettinger wrote: | | > To make the solutions equi-probable, a simple approach is to | > recursively enumerate all possibilities and then choose one of them | > with random.choice(). | | Maybe it is possible to

Re: number generator

2007-03-10 Thread Paul Rubin
Paulo da Silva <[EMAIL PROTECTED]> writes: > May be this is what you want ... > I didn't test it enough ... but seems fine. That's way too complicated. Think about Gerald Flanagan's description of the telegraph poles, and how to implement simply. It is a two liner. -- http://mail.python.org/mai

Re: number generator

2007-03-10 Thread Paulo da Silva
cesco escreveu: > I have to generate a list of N random numbers (integer) whose sum is > equal to M. If, for example, I have to generate 5 random numbers whose > sum is 50 a possible solution could be [3, 11, 7, 22, 7]. Is there a > simple pattern or function in Python to accomplish that? > > Than

Re: number generator

2007-03-10 Thread Mel Wilson
Gerard Flanagan wrote: > On Mar 9, 4:17 pm, "cesco" <[EMAIL PROTECTED]> wrote: >> On Mar 9, 3:51 pm, Paul Rubin wrote: >> >>> "cesco" <[EMAIL PROTECTED]> writes: I have to generate a list of N random numbers (integer) whose sum is equal to M. If, for example, I

Re: number generator

2007-03-10 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > Doesn't mean that it isn't random. After all, the first four numbers are > random, therefore their sum is random. 50 - (something random) is also > random. What does it mean for the first 4 numbers to be random? For example, is 27 random? By your met

Re: number generator

2007-03-10 Thread Anton Vredegoor
Raymond Hettinger wrote: > To make the solutions equi-probable, a simple approach is to > recursively enumerate all possibilities and then choose one of them > with random.choice(). Maybe it is possible to generate the possibilities by an indexing function and then use randint to pick one of the

  1   2   >