On 11/11/2013 11:19 AM, Robert Kern wrote:
On 2013-11-11 00:49, alex23 wrote:
The random module uses os.urandom,
No, it doesn't. random.random() is an alias to the random() method on
the random.Random class, which uses the Mersenne Twister to generate
values. os.urandom() gets called i
On 11/11/2013 01:15, Ned Batchelder wrote:
On Friday, November 8, 2013 12:48:04 PM UTC-5, Pascal Bit wrote:
Here's the code:
from random import random
from time import clock
s = clock()
for i in (1, 2, 3, 6, 8):
M = 0
N = 10**i
for n in xrange(N):
r = random()
On Friday, November 8, 2013 12:48:04 PM UTC-5, Pascal Bit wrote:
> Here's the code:
>
> from random import random
> from time import clock
>
> s = clock()
>
> for i in (1, 2, 3, 6, 8):
> M = 0
> N = 10**i
>
> for n in xrange(N):
> r = random()
> if 0.5 < r < 0.6
elf...
The python version in this case is 1.5 times faster...
I don't understand.
What causes this?
The random module uses os.urandom,
No, it doesn't. random.random() is an alias to the random() method on the
random.Random class, which uses the Mersenne Twister to generate values
is 1.5 times faster...
I don't understand.
What causes this?
The random module uses os.urandom, which relies on OS implementations of
randomness functionality:
"On a UNIX-like system this will query /dev/urandom, and on Windows it
will use CryptGenRandom()."
http://docs.py
Here's the code:
from random import random
from time import clock
s = clock()
for i in (1, 2, 3, 6, 8):
M = 0
N = 10**i
for n in xrange(N):
r = random()
if 0.5 < r < 0.6:
M += 1
k = (N, float(M)/N)
print (clock()-s)
Running on win7 python 2.7 32 b
.
2. hack the random module into something nonrandom
I think you can "import debug_random as random" and then have your
testee automatically pick up that module instead of the real one. Since
you already hardcoded the results to check against ("expected = ..." in
your code
07.02.12 00:06, Matej Cepl написав(ла):
> return seq[int(random.random() * len(seq))]
>
> doesn't seem like something so terrible (and maintenance intense). :)
_choice('abc') returns 'a' with probability P('a') =
1501199875790165/4503599627370496 = 1/3 - 1/13510798882111488 and 'b' with
probabi
I really don't care that much about distribution of my choice,
this function
def _choice(self, seq):
"""Choose a random element from a non-empty sequence.
Embedding random.choice from 2.6 in order to get an uniform
results between 2.6 and 3.2, wher
On 02/06/12 12:48, Aaron France wrote:
On 02/06/2012 09:57 AM, Matej Cepl wrote:
Silly, of course, the solution is obvious ... I have just
embedded random.choice from 2.6 to my code.
Matěj
Is the above actually a good idea though?
What I understand you're doing is embedding the source from
th
On 02/06/2012 09:57 AM, Matej Cepl wrote:
On 6.2.2012 09:45, Matej Cepl wrote:
Also, how could I write a re-implementation of random.choice which would
work same on python 2.6 and python 3.2? It is not only matter of unit
tests, but I would really welcome if the results on both versions
produce
Steven D'Aprano wrote:
> A more explicit note will help, but the basic problem applies: how do you
> write deterministic tests given that the random.methods (apart from
> random.random itself) can be changed without warning?
Biting the bullet would mean supplying your own PRNG, under your control
On 6.2.2012 09:45, Matej Cepl wrote:
Also, how could I write a re-implementation of random.choice which would
work same on python 2.6 and python 3.2? It is not only matter of unit
tests, but I would really welcome if the results on both versions
produce the same results.
Silly, of course, the s
On 6.2.2012 09:05, Steven D'Aprano wrote:
You have persuaded me that the doc should be more explicit that while
the basic random.random sequence will be kept repeatable with seed set
(except perhaps after a changeover of several releases), the convenience
transformations can be changed if improve
rwise improving them. This statement is not limited to the
> random module.
>
> You have persuaded me that the doc should be more explicit that while
> the basic random.random sequence will be kept repeatable with seed set
> (except perhaps after a changeover of several releases),
ving them. This statement is not limited to the
random module.
You have persuaded me that the doc should be more explicit that while
the basic random.random sequence will be kept repeatable with seed set
(except perhaps after a changeover of several releases), the convenience
transformations ca
On Mon, 06 Feb 2012 00:07:04 -0500, Terry Reedy wrote:
> On 2/5/2012 11:01 PM, Steven D'Aprano wrote:
>
>> Reading the docs, I would expect that when using an int as seed, you
>> should get identical results.
>
> That is similar to expecting hash to be consistent from version to
> version.
No.
an empty sequence')
return seq[i]
The change was announced in What's New in 3.2
random
The integer methods in the random module now do a better job of
producing uniform distributions. Previously, they computed selections
with int(n*random()) which had a slight bias whenever n was no
On Mon, 06 Feb 2012 02:27:38 +0100, Matej Cepl wrote:
> Strange thing is that this unit tests correctly with python3, but fails
> with python2. The problem is that apparently python3 random.choice picks
> different element of self[k] than the one python2 (at least, both of
> them are constant in t
Hi,
I have this working function:
def as_xml(self):
out = etree.Element("or")
for k in sorted(self.keys()):
out.append(etree.Element("hostname",
attrib={'op': '=', 'value': random.choice(self[k])}))
# ... return somehow string representing
: Random module missing?
On Wed, Sep 23, 2009 at 5:00 PM, Brown, Rodrick wrote:
> I seen some documentation about random.random() but my version seems to be
> broken?
>
> Python 2.3.4 (#1, Jul 16 2009, 07:03:37) [GCC 3.4.6 20060404 (Red Hat
> 3.4.6-11)] on linux2 Type "help&quo
On 2009-09-23 16:00 PM, Brown, Rodrick wrote:
I seen some documentation about random.random() but my version seems to be
broken?
Python 2.3.4 (#1, Jul 16 2009, 07:03:37)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
imp
On Wed, Sep 23, 2009 at 5:00 PM, Brown, Rodrick wrote:
> I seen some documentation about random.random() but my version seems to be
> broken?
>
> Python 2.3.4 (#1, Jul 16 2009, 07:03:37)
> [GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2
> Type "help", "copyright", "credits" or "license" for mor
I seen some documentation about random.random() but my version seems to be
broken?
Python 2.3.4 (#1, Jul 16 2009, 07:03:37)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>> dir(random)
['__builtins__', '
On Wed, Sep 2, 2009 at 2:15 PM, Raymond Hettinger wrote:
> ISTM, there ought to be a statistics module that can calculate
> cumulative distribution functions for a variety of distributions.
> This would be far more helpful than creating more generators.
>
Many of the formulas for cumulative dist
Robert Kern wrote:
On 2009-09-02 14:15 PM, Raymond Hettinger wrote:
On Sep 2, 6:51 am, Thomas Philips wrote:
While the random module allows one to generate randome numbers with a
variety of distributions, some useful distributions are omitted - the
Student's t being among them.
I'
On 2009-09-02 14:15 PM, Raymond Hettinger wrote:
On Sep 2, 6:51 am, Thomas Philips wrote:
While the random module allows one to generate randome numbers with a
variety of distributions, some useful distributions are omitted - the
Student's t being among them.
I'm curious to hear
On Sep 2, 2:37 pm, Mark Dickinson wrote:
> On Sep 2, 6:15 pm, Thomas Philips wrote:
>
> > I mis-spoke - the variance is infinite when df=2 (the variance is df/
> > (df-2),
>
> Yes: the variance is infinite both for df=2 and df=1, and Student's t
> with df=1 doesn't even have an expectation. I d
> To get this into core Python, you'd usually submit a feature request
> athttp://bugs.python.org.
If you do submit a patch, please assign it to me.
I've been the primary maintainer for that module
for several years.
Raymond Hettinger
--
http://mail.python.org/mailman/listinfo/python-list
On Sep 2, 6:51 am, Thomas Philips wrote:
> While the random module allows one to generate randome numbers with a
> variety of distributions, some useful distributions are omitted - the
> Student's t being among them.
I'm curious to hear what your use cases are.
My unde
On Sep 2, 6:15 pm, Thomas Philips wrote:
> I mis-spoke - the variance is infinite when df=2 (the variance is df/
> (df-2),
Yes: the variance is infinite both for df=2 and df=1, and Student's t
with df=1 doesn't even have an expectation. I don't see why this
would stop you from generating meanin
On 2009-09-02 11:28 AM, Mark Dickinson wrote:
On Sep 2, 2:51 pm, Thomas Philips wrote:
def student_t(df): # df is the number of degrees of freedom
if df< 2 or int(df) != df:
raise ValueError, 'student_tvariate: df must be a integer> 1'
By the way, why do you exclude th
On Sep 2, 1:03 pm, Thomas Philips wrote:
> On Sep 2, 12:28 pm, Mark Dickinson wrote:
>
> > On Sep 2, 2:51 pm, Thomas Philips wrote:
>
> > > def student_t(df): # df is the number of degrees of freedom
> > > if df < 2 or int(df) != df:
> > > raise ValueError, 'student_tvariate:
On Sep 2, 12:28 pm, Mark Dickinson wrote:
> On Sep 2, 2:51 pm, Thomas Philips wrote:
>
> > def student_t(df): # df is the number of degrees of freedom
> > if df < 2 or int(df) != df:
> > raise ValueError, 'student_tvariate: df must be a integer > 1'
>
> By the way, why do you
On Sep 2, 2:51 pm, Thomas Philips wrote:
> def student_t(df): # df is the number of degrees of freedom
> if df < 2 or int(df) != df:
> raise ValueError, 'student_tvariate: df must be a integer > 1'
By the way, why do you exclude the possibility df=1 here?
--
Mark
--
http://m
On Sep 2, 2:51 pm, Thomas Philips wrote:
> While the random module allows one to generate randome numbers with a
> variety of distributions, some useful distributions are omitted - the
> Student's t being among them. This distribution is easily derived from
> the normal distrib
While the random module allows one to generate randome numbers with a
variety of distributions, some useful distributions are omitted - the
Student's t being among them. This distribution is easily derived from
the normal distribution and the chi-squared distribution (which in
turn is a sp
On Mar 4, 12:33 am, "Diez B. Roggisch" wrote:
> > So far I get the same results under Mac OS X, Windows, and Linux
> > (Google App Engine). I'm particularly interested in getting the same
> > results under the Google App Engine even as Google upgrades its
> > servers over time.
>
> I just had a l
Paul Rubin schrieb:
"Diez B. Roggisch" writes:
Random uses AFAIK rand/srand from the stdlib.h of your platform (*nix,
no idea how that beast is called in redmond).
According to http://docs.python.org/library/random.html
it uses Mersenne Twister.
Yeah, I figured that out later, sorry for th
"Diez B. Roggisch" writes:
> Random uses AFAIK rand/srand from the stdlib.h of your platform (*nix,
> no idea how that beast is called in redmond).
According to http://docs.python.org/library/random.html
it uses Mersenne Twister.
--
http://mail.python.org/mailman/listinfo/python-list
So far I get the same results under Mac OS X, Windows, and Linux
(Google App Engine). I'm particularly interested in getting the same
results under the Google App Engine even as Google upgrades its
servers over time.
I just had a look into the python source - and I was wrong, it appears
rando
On Mar 4, 2:26 am, "Diez B. Roggisch" wrote:
> Amir Michail schrieb:
>
> > On Mar 3, 10:05 pm, Chris Rebert wrote:
> >> On Tue, Mar 3, 2009 at 6:59 PM, Amir Michail wrote:
> >>> Hi,
> >>> Is it the case that the random module will always gi
Amir Michail schrieb:
On Mar 3, 10:05 pm, Chris Rebert wrote:
On Tue, Mar 3, 2009 at 6:59 PM, Amir Michail wrote:
Hi,
Is it the case that the random module will always give the same
results if given the same seed across all configurations (e.g.,
architectures, compilers, etc.)?
Your
On Mar 3, 6:59 pm, Amir Michail wrote:
> Hi,
>
> Is it the case that the random module will always give the same
> results if given the same seed across all configurations (e.g.,
> architectures, compilers, etc.)?
If you need a repeatable sequence, such as for unit testing, y
On Tue, Mar 3, 2009 at 7:11 PM, Amir Michail wrote:
> On Mar 3, 10:05 pm, Chris Rebert wrote:
>> On Tue, Mar 3, 2009 at 6:59 PM, Amir Michail wrote:
>> > Hi,
>>
>> > Is it the case that the random module will always give the same
>> > results if giv
On Mar 3, 10:05 pm, Chris Rebert wrote:
> On Tue, Mar 3, 2009 at 6:59 PM, Amir Michail wrote:
> > Hi,
>
> > Is it the case that the random module will always give the same
> > results if given the same seed across all configurations (e.g.,
> > architectures, compi
On Tue, Mar 3, 2009 at 6:59 PM, Amir Michail wrote:
> Hi,
>
> Is it the case that the random module will always give the same
> results if given the same seed across all configurations (e.g.,
> architectures, compilers, etc.)?
Your question is vague. Define what you mean by &q
Hi,
Is it the case that the random module will always give the same
results if given the same seed across all configurations (e.g.,
architectures, compilers, etc.)?
Amir
--
http://mail.python.org/mailman/listinfo/python-list
On Jul 12, 10:06 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Fri, 11 Jul 2008 12:27:32 -0700, castironpi wrote:
> > You want a random integer. Is there a range you want it in?
>
> > Past a certain point, you'll exceed the granularity of the random number
> > generator, a
On Fri, 11 Jul 2008 12:27:32 -0700, castironpi wrote:
> You want a random integer. Is there a range you want it in?
>
> Past a certain point, you'll exceed the granularity of the random number
> generator, and some values in the range will never be generated.
You might want to produce an unboun
On Fri, 11 Jul 2008 12:27:32 -0700, castironpi wrote:
> On Jul 11, 1:29 pm, WDC <[EMAIL PROTECTED]> wrote:
>> On Jul 11, 2:15 pm, Michiel Overtoom <[EMAIL PROTECTED]> wrote:
>>
>> > You wrote...
>> > >Is there a better way to do that besides doing this:
>>
>> > random.randint(0
On Jul 11, 1:29 pm, WDC <[EMAIL PROTECTED]> wrote:
> On Jul 11, 2:15 pm, Michiel Overtoom <[EMAIL PROTECTED]> wrote:
>
> > You wrote...
> > >Is there a better way to do that besides doing this:
>
> > random.randint(0, 9)
> > >09657398671238769
>
> > Maybe this?
>
On Jul 11, 2:15 pm, Michiel Overtoom <[EMAIL PROTECTED]> wrote:
> You wrote...
> >Is there a better way to do that besides doing this:
>
> random.randint(0, 9)
> >09657398671238769
>
> Maybe this?
>
> random.randint(0, 9e16)
>
> --
> "The ability of the O
You wrote...
>Is there a better way to do that besides doing this:
>
random.randint(0, 9)
>09657398671238769
Maybe this?
random.randint(0, 9e16)
--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals
I am currently learning, and loving, Python and have a question about
random().
Right now, what I have to do to get a whole number and not a decimal
using random.random() is this:
>>>random.random()
0.84765728501856734
>>>_ * 10**17
84765728501856734.0
Is there a better way to do that besides do
On Sep 13, 12:57 am, Tim Roberts <[EMAIL PROTECTED]> wrote:
> Andrew F <[EMAIL PROTECTED]> wrote:
> >I'm a linux user and I just upgraded from 2.1 to 2.5 and changed the
> >location of a number of libraries and tools.
>
> >So far I've tracked most errors, but this one has me scratching my
> >head :
Andrew F <[EMAIL PROTECTED]> wrote:
>I'm a linux user and I just upgraded from 2.1 to 2.5 and changed the
>location of a number of libraries and tools.
>
>So far I've tracked most errors, but this one has me scratching my
>head :
>
>$ which python
>/usr/local/bin/python
>$ echo $PYTHONPATH
>/usr/l
object is not callable
You have a file called random.py in your current directory. It's
shadowing the random module from the library.
HTH,
--
Carsten Haese
http://informixdb.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list
I'm a linux user and I just upgraded from 2.1 to 2.5 and changed the
location of a number of libraries and tools.
So far I've tracked most errors, but this one has me scratching my
head :
$ which python
/usr/local/bin/python
$ echo $PYTHONPATH
/usr/local/bin/python
$ python
Python 2.5.1 (r251:548
Moishy Gluck wrote:
> I am using the random module to generate a session tracker. I use this
> code to generate a random number "random.random() * 1"
> The session is stored in a mysql database under the field session_id.
> The problem is when I try to su
HiI am using the random module to generate a session tracker. I use this code to generate a random number "random.random() * 1" The session is stored in a mysql database under the field session_id. The problem is when I try to submit the random number into my database
In article <[EMAIL PROTECTED]>,
"Carl Banks" <[EMAIL PROTECTED]> wrote:
> Ben Finney wrote:
> > "DataSmash" <[EMAIL PROTECTED]> writes:
> > > * random.py:
> > >
> > > import random
> >
> > Now that you've tripped over this ambiguity of Python's current
> > 'import' behaviour, you may be intereste
Ben Finney wrote:
> "DataSmash" <[EMAIL PROTECTED]> writes:
> > * random.py:
> >
> > import random
>
> Now that you've tripped over this ambiguity of Python's current
> 'import' behaviour, you may be interested to know that the behaviour
> will change to solve this:
>
> http://www.python.org/de
"DataSmash" <[EMAIL PROTECTED]> writes:
> * random.py:
>
> import random
Now that you've tripped over this ambiguity of Python's current
'import' behaviour, you may be interested to know that the behaviour
will change to solve this:
http://www.python.org/dev/peps/pep-0328/>
In brief: Python
Wow. Six simultaneous responses! Python rocks!
Anyway, I actually tried it, and persisted through the secondary
confusion about the lurking .pyc file, so even though I'm in sixth
place I get points for completeness...
mt
--
http://mail.python.org/mailman/listinfo/python-list
You must rename Your script.
Your script doesn't same name as calling module.
Tomas Brabenec
http://brabenec.net
DataSmash napsal(a):
> Hi,
> When I import the random module at the python interpreter, it works
> fine:
>
>>>> import random
>>>&
Much Thanks!
I deleted the random.pyc and renamed the script and everything is good!
R.D.
--
http://mail.python.org/mailman/listinfo/python-list
Much Thanks!
I deleted the random.pyc and renamed the script and everything is good!
R.D.
--
http://mail.python.org/mailman/listinfo/python-list
"Benjamin Niemann" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Don't name your script 'random.py' (or any other name from the stdlib).
> 'import random' will import the script itself (not the random module from
> the stdlib), wh
1) remove the file random.pyc in your working directory
2) rename the file random.py to something else and run it.
The import mechanism is looking for random.pyc or random.py, but you
have already named your file that! Your current directory is above your
library directory in python's search path
DataSmash wrote:
> Hi,
> When I import the random module at the python interpreter, it works
> fine:
> >>> import random
> >>> x = random.randint(1,55)
> >>> print x
> 14
> >>>
>
> BUT, when I put the same code in a python sc
"DataSmash" <[EMAIL PROTECTED]> writes:
> Hi,
> When I import the random module at the python interpreter, it works
> fine:
>>>> import random
>>>> x = random.randint(1,55)
>>>> print x
> 14
>>>>
>
> BUT, w
DataSmash wrote:
> Hi,
> When I import the random module at the python interpreter, it works
> fine:
>>>> import random
>>>> x = random.randint(1,55)
>>>> print x
> 14
>
> BUT, when I put the same code in a python script:
> * random.py:
&
DataSmash wrote:
> Hi,
> When I import the random module at the python interpreter, it works
> fine:
>>>> import random
>>>> x = random.randint(1,55)
>>>> print x
> 14
>>>>
>
> BUT, when I put the same code in a python scri
DataSmash wrote:
> Hi,
> When I import the random module at the python interpreter, it works
> fine:
>>>> import random
>>>> x = random.randint(1,55)
>>>> print x
> 14
>>>>
>
> BUT, when I put the same code in a python script:
&g
Hi,
When I import the random module at the python interpreter, it works
fine:
>>> import random
>>> x = random.randint(1,55)
>>> print x
14
>>>
BUT, when I put the same code in a python script:
* random.py:
import random
x = random.randint(1,55)
print x
a
>> Is Mersenne Twister currently available at all in Jython, for example?
Googling for "java mersenne twister" provides multiple hits including:
http://www.axlradius.com/freestuff/Free.htm#MT
Raymond
--
http://mail.python.org/mailman/listinfo/python-list
Raymond Hettinger wrote:
> The answer is a qualified Yes. While the core generator (currently
Thanks! That is the answer I'm looking for.
And to Paul Rubin, it is a good point that Jython might not support it, but
at this point it doesn't interest me. The program is only for myself
anyway.
"Raymond Hettinger" <[EMAIL PROTECTED]> writes:
> >> Can I rely on the random.py module to produce the same series of
> >> numbers for future/past versions of Python, given the same seed?
>
> The answer is a qualified Yes. While the core generator (currently the
> Mersenne Twister algorithm) is s
>> Can I rely on the random.py module to produce the same series of
>> numbers for future/past versions of Python, given the same seed?
The answer is a qualified Yes. While the core generator (currently the
Mersenne Twister algorithm) is subject to change across versions,
whenever we've updated t
"Roose" <[EMAIL PROTECTED]> writes:
> Can I rely on the random.py module to produce the same series of numbers for
> future/past versions of Python, given the same seed? Can I rely on it
> across different architectures and operating systems?
>
> I looked at the docs and couldn't find this stat
Can I rely on the random.py module to produce the same series of numbers for
future/past versions of Python, given the same seed? Can I rely on it
across different architectures and operating systems?
I looked at the docs and couldn't find this stated anywhere. My feeling is
yes, but it's a f
Will McGugan wrote:
Hi,
If I retrieve the hash of an integer, will it always return the same
value across platforms?
This reason I ask is that I want to produce a sequence of pseudo random
numbers using the random module, that I can re-create later on. So I'll
need to store the seed value
Hi,
If I retrieve the hash of an integer, will it always return the same
value across platforms?
This reason I ask is that I want to produce a sequence of pseudo random
numbers using the random module, that I can re-create later on. So I'll
need to store the seed value, but Random.seed ta
84 matches
Mail list logo