Re: True randominess
On 8/4/05, Scott Gifford [EMAIL PROTECTED] wrote: Pat Adams [EMAIL PROTECTED] writes: 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/ftp.mysql.com/doc/en/Adding_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/[EMAIL PROTECTED] Thanks for the wonderful sources! -- Power to people, Linux is here.
True randominess
I've noticed that rand() do not change on each query request. Is there a way I could get a TRUE randominess into MySQL? -- Power to people, Linux is here.
Re: True randominess
On Thu, 2005-08-04 at 15:00 -0400, Scott Hamm wrote: I've noticed that rand() do not change on each query request. Is there a way I could get a TRUE randominess into MySQL? http://dev.mysql.com/doc/mysql/en/mathematical-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(); +--+--+--+ | rand(3) | rand() | rand() | +--+--+--+ | 0.18109050875631 | 0.75023213843837 | 0.20788919665654 | +--+--+--+ 1 row in set (0.00 sec) mysql SELECT rand(), rand(), rand(); +--+--+--+ | rand() | rand() | rand() | +--+--+--+ | 0.78874959870125 | 0.32008043427028 | 0.23415340598128 | +--+--+--+ 1 row in set (0.01 sec) mysql SELECT rand(3), rand(), rand(); +--+--+--+ | 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. -- Pat Adams Applications Programmer SYSCO Food Services of Dallas signature.asc Description: This is a digitally signed message part
Re: True randominess
Pat Adams wrote: 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/[EMAIL PROTECTED]
Re: True randominess
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. 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. -- Pat Adams Applications Programmer SYSCO Food Services of Dallas signature.asc Description: This is a digitally signed message part
Re: True randominess
Pat Adams [EMAIL PROTECTED] writes: 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/ftp.mysql.com/doc/en/Adding_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/[EMAIL PROTECTED]