Seeding the rand() Generator

Jarkko Torppa torppa at staff.megabaud.fi
Tue Aug 4 09:12:30 CEST 2009


On 2009-08-04, Fred Atkinson <fatkinson at mishmash.com> wrote:
> On Mon, 3 Aug 2009 20:00:08 -0700 (PDT), Carl Banks
><pavlovevidence at gmail.com> wrote:
>>
>>If you don't "get" why this is a MySQL question and not a Python
>>question, then you need to learn more about what you are doing.
>
> 	I wouldn't agree.  
>
> 	I tried using the same command I used when I did this in PHP.
> That command was: mt_srand(date("w"))
>
> 	It was a PHP command that seeds the MySQL random function,
> according to the folks on the PHP newsgroup.  

It seems that they lied to you. Did you actually try that ?

> 	I'm trying to figure out what the Python equivalent of that
> is.  

Python equivalent of that is random.seed(x), if PHP docs are to be believed.

> 	Now do you see?  

What you acutally want is "select *,rand(3) as rand from table
order by rand" or something like that. That 3 is the seed in there.

-- 
Jarkko Torppa



More information about the Python-list mailing list