dbTalk Databases Forums  

True randominess

mailing.database.myodbc mailing.database.myodbc


Discuss True randominess in the mailing.database.myodbc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Scott Hamm
 
Posts: n/a

Default True randominess - 08-04-2005 , 02:00 PM






------=_Part_432_25553444.1123182033203
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I've noticed that rand() do not change on each query request. Is there a wa=
y=20
I could get a TRUE randominess into MySQL?

--=20
Power to people, Linux is here.

------=_Part_432_25553444.1123182033203--

Reply With Quote
  #2  
Old   
Pat Adams
 
Posts: n/a

Default Re: True randominess - 08-04-2005 , 02:14 PM






--=-ok8rgGiT+Ljf+jMbaaIq
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

On Thu, 2005-08-04 at 15:00 -0400, Scott Hamm wrote:
Quote:
I've noticed that rand() do not change on each query request. Is there a =
way=20
I could get a TRUE randominess into MySQL?
http://dev.mysql.com/doc/mysql/en/ma...functions.html

Are you using RAND() or RAND(n)? Using RAND() makes MySQL choose its own
seed (the documentation doesn't specify what seed it will use). If you
choose to seed the random number generator (for example, RAND(3)) and
then start using RAND() it will produce a repeatable sequence.

mysql> SELECT rand(3), rand(), rand();
+------------------+------------------+------------------+
Quote:
rand(3) | rand() | rand() |
+------------------+------------------+------------------+
0.18109050875631 | 0.75023213843837 | 0.20788919665654 |
+------------------+------------------+------------------+
1 row in set (0.00 sec)

mysql> SELECT rand(), rand(), rand();
+------------------+------------------+------------------+
Quote:
rand() | rand() | rand() |
+------------------+------------------+------------------+
0.78874959870125 | 0.32008043427028 | 0.23415340598128 |
+------------------+------------------+------------------+
1 row in set (0.01 sec)

mysql> SELECT rand(3), rand(), rand();
+------------------+------------------+------------------+
Quote:
rand(3) | rand() | rand() |
+------------------+------------------+------------------+
0.18109050875631 | 0.75023213843837 | 0.20788919665654 |
+------------------+------------------+------------------+
1 row in set (0.00 sec)

Notice that the numbers after calling RAND(3) are in the same sequence.

However, in answer to your question, there is no way to get TRUE
randomness in a computer system. Even cryptographically secure random
number generators can be predicted under absolutely identical
circumstances.

--=20
Pat Adams
Applications Programmer
SYSCO Food Services of Dallas

--=-ok8rgGiT+Ljf+jMbaaIq
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBC8mkKAyDa4wKsEz4RAvF5AJ9zIyRKI+zn5XuVeTOfYq S7zsBCBQCgtkio
2KWmgQ/qHS0MeuevT8tzGjI=
=nP6V
-----END PGP SIGNATURE-----

--=-ok8rgGiT+Ljf+jMbaaIq--


Reply With Quote
  #3  
Old   
2wsxdr5
 
Posts: n/a

Default Re: True randominess - 08-04-2005 , 02:50 PM



Pat Adams wrote:

Quote:
However, in answer to your question, there is no way to get TRUE
randomness in a computer system. Even cryptographically secure random
number generators can be predicted under absolutely identical
circumstances.


While technically that is true, there is a method that will give what I
think is a very random number and is extremely unlikely to produce the
same sequence. What you do is seed the random number generator with an
integer based on the system time. Unless the random number is generated
at the same time every day, you will have very random out put. If it is
done at the same time every day you can use the date as part of your
seed. Depending on the frequency at which these random numbers need to
be generated, you may wish to use fractions of a second or just seconds.

There are also several places that you can get a reasonably random
number for the seed from your machine. The amount of free disk space,
unless that doesn't change much on your machine. The amount of free
RAM, (up time mod cpu usage). Any number of things could be used that
are not very predictable, if at all.


--
Chris W

Gift Giving Made Easy
Get the gifts you want &
give the gifts they want
http://thewishzone.com


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=m...ie.nctu.edu.tw



Reply With Quote
  #4  
Old   
Pat Adams
 
Posts: n/a

Default Re: True randominess - 08-04-2005 , 02:53 PM



--=-uFoha7HmETYiw+A+JQ2V
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

On Thu, 2005-08-04 at 14:44 -0500, 2wsxdr5 wrote:
Quote:
There are also several places that you can get a reasonably random=20
number for the seed from your machine. The amount of free disk space,=20
unless that doesn't change much on your machine. The amount of free=20
RAM, (up time mod cpu usage). Any number of things could be used that=20
are not very predictable, if at all.
But again, those aren't truely random. They're random-enough for the
average web applications. The original poster, if memory serves, asked
if it was possible to get true random numbers from MySQL. True random
numbers can't be predicted even if I know everything about your system.
Because computers are predictable beasts, the random number generators
that they used are constrained by the hardware limits.

But it's really just a semantic difference. Seeding with digits from the
least significant part of a UNIX timestamp would be sufficient to seed a
RNG randomly enough for average web applications, but it's not truely
random, since a web log will show what time the user hit the
application, and you can figure out what the RNG was seeded with at that
point.=20
--=20
Pat Adams
Applications Programmer
SYSCO Food Services of Dallas

--=-uFoha7HmETYiw+A+JQ2V
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBC8nIcAyDa4wKsEz4RAu5UAJ92PN67DgNVN7x2J+LlNy TtVl+pRgCeLYYB
TKmV1/zFIP7MsCsVnWqTjCA=
=HGnk
-----END PGP SIGNATURE-----

--=-uFoha7HmETYiw+A+JQ2V--


Reply With Quote
  #5  
Old   
Scott Gifford
 
Posts: n/a

Default Re: True randominess - 08-04-2005 , 08:42 PM



Pat Adams <adams.patrick (AT) dallas (DOT) sysco.com> writes:

Quote:
On Thu, 2005-08-04 at 14:44 -0500, 2wsxdr5 wrote:
There are also several places that you can get a reasonably random
number for the seed from your machine. The amount of free disk space,
unless that doesn't change much on your machine. The amount of free
RAM, (up time mod cpu usage). Any number of things could be used that
are not very predictable, if at all.

But again, those aren't truely random. They're random-enough for the
average web applications. The original poster, if memory serves, asked
if it was possible to get true random numbers from MySQL. True random
numbers can't be predicted even if I know everything about your system.
Because computers are predictable beasts, the random number generators
that they used are constrained by the hardware limits.
/dev/random is a source of some genuine entropy on many Unix-like
operating systems. It uses variations in system timings that are
believed to be truly random. It's not good for a large volume of
output, but it's a good seed. You could probably incorporate access
to it or its friend /dev/urandom as a UDF:

http://sunsite.mff.cuni.cz/MIRRORS/f...dding_UDF.html

EGD (Entropy Gathering Daemon) is an option for other Unix-like
systems:

http://egd.sourceforge.net/

or you can use a Lava Lamp:

http://www.lavarnd.org/index.html

I'm sure Windows has some way to do this, too.

Many systems also have an onboard random number generator which you
should be able to access through an OS driver.

----ScottG.

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=m...ie.nctu.edu.tw



Reply With Quote
  #6  
Old   
Scott Hamm
 
Posts: n/a

Default Re: True randominess - 08-05-2005 , 06:32 AM



------=_Part_954_31132359.1123241556043
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On 8/4/05, Scott Gifford <sgifford (AT) suspectclass (DOT) com> wrote:
Quote:
=20
Pat Adams <adams.patrick (AT) dallas (DOT) sysco.com> writes:
=20
On Thu, 2005-08-04 at 14:44 -0500, 2wsxdr5 wrote:
There are also several places that you can get a reasonably random
number for the seed from your machine. The amount of free disk space,
unless that doesn't change much on your machine. The amount of free
RAM, (up time mod cpu usage). Any number of things could be used that
are not very predictable, if at all.

But again, those aren't truely random. They're random-enough for the
average web applications. The original poster, if memory serves, asked
if it was possible to get true random numbers from MySQL. True random
numbers can't be predicted even if I know everything about your system.
Because computers are predictable beasts, the random number generators
that they used are constrained by the hardware limits.
=20
/dev/random is a source of some genuine entropy on many Unix-like
operating systems. It uses variations in system timings that are
believed to be truly random. It's not good for a large volume of
output, but it's a good seed. You could probably incorporate access
to it or its friend /dev/urandom as a UDF:
=20
http://sunsite.mff.cuni.cz/MIRRORS/f...dding_UDF.html
=20
EGD (Entropy Gathering Daemon) is an option for other Unix-like
systems:
=20
http://egd.sourceforge.net/
=20
or you can use a Lava Lamp:
=20
http://www.lavarnd.org/index.html
=20
I'm sure Windows has some way to do this, too.
=20
Many systems also have an onboard random number generator which you
should be able to access through an OS driver.
=20
----ScottG.
=20
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3...mail (DOT) com
=20
Thanks for the wonderful sources!

--=20
Power to people, Linux is here.

------=_Part_954_31132359.1123241556043--


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.