Seeding the rand() Generator

Carl Banks pavlovevidence at gmail.com
Mon Aug 3 23:00:08 EDT 2009


On Aug 3, 8:12 pm, Fred Atkinson <fatkin... at mishmash.com> wrote:
> On Sun, 2 Aug 2009 17:00:40 -0700 (PDT), Carl Banks
>
> <pavlovevide... at gmail.com> wrote:
>
>         I appreciate the response.  
>
>         I am executing a statement to retrieve one record at random.  
>
>         An example would be: SELECT first, second, third, fourth,
> fifth, sixth from sometable order by rand() limit 1
>
>         It would be contained as: stmt = "SELECT first, second, third,
> fourth, fifth, sixth from sometable order by rand() limit 1"
>
>         Then I would execute it with the command: cursor.execute(stmt)
>
>         How would I correctly seed the random generator in the MySQL
> statement from within Python?  


You apparently know how to run MySQL statements from Python, correct?

You also apparently know how to run a particular MySQL statement from
PHP that seeds the random number generator, correct?

Given those two apparent facts, you should be able run whatever
statement you ran in PHP to seed the RNG in Python.  So I don't see
what the problem is.

Your question is a MySQL question, not a Python question.  I don't
know off hand how to seed the RNG in MySQL, and, since this is a
Python group and not a MySQL group, I don't care to look it up.  But
if you were able to produce the MySQL statement in PHP that does it
you shouldn't need to ask.

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.


Carl Banks



More information about the Python-list mailing list