Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-29-2008, 08:28 PM
Cosmic programmer
 
Posts: n/a
Default RAND()

How good is the rand function of MySQL? How can it be improved?

Thx.

--
When you argue with a fool, chances are he's doing the same


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-29-2008, 08:28 PM
Jerry Stuckle
 
Posts: n/a
Default Re: RAND()

Cosmic programmer wrote:
> How good is the rand function of MySQL? How can it be improved?
>
> Thx.
>
> --
> When you argue with a fool, chances are he's doing the same
>
>
>


It's as good as pretty much any pseudo-random number generator. Why do
you think it needs to be improved?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-29-2008, 08:28 PM
Captain Paralytic
 
Posts: n/a
Default Re: RAND()

On 29 Apr, 13:03, "Cosmic programmer" <not-my-em...@nowhere.com>
wrote:
> How good is the rand function of MySQL? How can it be improved?
>
> Thx.
>
> --
> When you argue with a fool, chances are he's doing the same


How do you define good?
Depending on your criteria it is:
Very Good
Good
Not Very Good
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-29-2008, 08:28 PM
ZeldorBlat
 
Posts: n/a
Default Re: RAND()

On Apr 29, 9:03 am, "Cosmic programmer" <not-my-em...@nowhere.com>
wrote:
> How good is the rand function of MySQL? How can it be improved?
>
> Thx.
>
> --
> When you argue with a fool, chances are he's doing the same


From the manual:

<http://dev.mysql.com/doc/refman/5.0/en/mathematical-
functions.html#function_rand>

"RAND() is not meant to be a perfect random generator, but instead is
a fast way to generate ad hoc random numbers which is portable between
platforms for the same MySQL version."

So I suppose it's up to you to decide how "good" it is.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-02-2008, 05:05 AM
Tigger
 
Posts: n/a
Default Re: RAND()


"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
news:n8GdnZSDT8M7gIrVnZ2dnUVZ_vKdnZ2d@comcast.com. ..
> Cosmic programmer wrote:
>> How good is the rand function of MySQL? How can it be improved?
>>
>> Thx.
>>
>> --
>> When you argue with a fool, chances are he's doing the same

>
> It's as good as pretty much any pseudo-random number generator. Why do
> you think it needs to be improved?
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================
>


I remember an older version had issues with generating the same random
number sequences when called from identical code routines.

The solution was to add a random seed from the language your using to
shuffle the pack first, so to speak.

--
Tony
http://www.mccreath.org.uk


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 05-02-2008, 05:05 AM
Nick Wedd
 
Posts: n/a
Default Re: RAND()

In message <n8GdnZSDT8M7gIrVnZ2dnUVZ_vKdnZ2d@comcast.com>, Jerry Stuckle
<jstucklex@attglobal.net> writes
>Cosmic programmer wrote:
>> How good is the rand function of MySQL? How can it be improved?
>> Thx.
>> --
>> When you argue with a fool, chances are he's doing the same

>
>It's as good as pretty much any pseudo-random number generator. Why do
>you think it needs to be improved?


If it's only as good as any pseudo-random number generator, it
definitely needs to be improved.

Nick

--
Nick Wedd nick@maproom.co.uk
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 05-02-2008, 05:05 AM
Jerry Stuckle
 
Posts: n/a
Default Re: RAND()

Tigger wrote:
> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
> news:n8GdnZSDT8M7gIrVnZ2dnUVZ_vKdnZ2d@comcast.com. ..
>> Cosmic programmer wrote:
>>> How good is the rand function of MySQL? How can it be improved?
>>>
>>> Thx.
>>>
>>> --
>>> When you argue with a fool, chances are he's doing the same

>> It's as good as pretty much any pseudo-random number generator. Why do
>> you think it needs to be improved?
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstucklex@attglobal.net
>> ==================
>>

>
> I remember an older version had issues with generating the same random
> number sequences when called from identical code routines.
>
> The solution was to add a random seed from the language your using to
> shuffle the pack first, so to speak.
>


Any pseudo random number generator will generate the same sequence if
you start with the same seed. But if you don't give it a seed, it picks
one up from the system (clock? don't know what it uses for sure).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 05-02-2008, 05:05 AM
Jerry Stuckle
 
Posts: n/a
Default Re: RAND()

Nick Wedd wrote:
> In message <n8GdnZSDT8M7gIrVnZ2dnUVZ_vKdnZ2d@comcast.com>, Jerry Stuckle
> <jstucklex@attglobal.net> writes
>> Cosmic programmer wrote:
>>> How good is the rand function of MySQL? How can it be improved?
>>> Thx.
>>> --
>>> When you argue with a fool, chances are he's doing the same

>>
>> It's as good as pretty much any pseudo-random number generator. Why
>> do you think it needs to be improved?

>
> If it's only as good as any pseudo-random number generator, it
> definitely needs to be improved.
>
> Nick
>


And exactly how would you do that? Most pseudo-random number generators
are pretty good, IMHO. And there is no such thing as a true random
number generator.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 05-02-2008, 05:05 AM
Nick Wedd
 
Posts: n/a
Default Re: RAND()

In message <69qdnTw3ffk8Z4TVnZ2dnUVZ_qfinZ2d@comcast.com>, Jerry Stuckle
<jstucklex@attglobal.net> writes
>Nick Wedd wrote:
>> In message <n8GdnZSDT8M7gIrVnZ2dnUVZ_vKdnZ2d@comcast.com>, Jerry
>>Stuckle <jstucklex@attglobal.net> writes
>>> Cosmic programmer wrote:
>>>> How good is the rand function of MySQL? How can it be improved?
>>>> Thx.
>>>> --
>>>> When you argue with a fool, chances are he's doing the same
>>>
>>> It's as good as pretty much any pseudo-random number generator. Why
>>>do you think it needs to be improved?

>> If it's only as good as any pseudo-random number generator, it
>>definitely needs to be improved.
>> Nick
>>

>
>And exactly how would you do that? Most pseudo-random number
>generators are pretty good, IMHO. And there is no such thing as a true
>random number generator.


Knuth's "Numerical recipes in C" explains what can be wrong with
system-supplied rand() functions. He wrote it 20 years ago, and things
must have improved since then; but I still wouldn't trust a
system-supplied rand(). He gives code for improving a system rand(),
also for replacing it by one known to be good. His code is in C of
course, but is quite short and is easily translated into other
languages.

Nick
--
Nick Wedd nick@maproom.co.uk
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 05-02-2008, 05:05 AM
Jerry Stuckle
 
Posts: n/a
Default Re: RAND()

Nick Wedd wrote:
> In message <69qdnTw3ffk8Z4TVnZ2dnUVZ_qfinZ2d@comcast.com>, Jerry Stuckle
> <jstucklex@attglobal.net> writes
>> Nick Wedd wrote:
>>> In message <n8GdnZSDT8M7gIrVnZ2dnUVZ_vKdnZ2d@comcast.com>, Jerry
>>> Stuckle <jstucklex@attglobal.net> writes
>>>> Cosmic programmer wrote:
>>>>> How good is the rand function of MySQL? How can it be improved?
>>>>> Thx.
>>>>> --
>>>>> When you argue with a fool, chances are he's doing the same
>>>>
>>>> It's as good as pretty much any pseudo-random number generator. Why
>>>> do you think it needs to be improved?
>>> If it's only as good as any pseudo-random number generator, it
>>> definitely needs to be improved.
>>> Nick
>>>

>>
>> And exactly how would you do that? Most pseudo-random number
>> generators are pretty good, IMHO. And there is no such thing as a
>> true random number generator.

>
> Knuth's "Numerical recipes in C" explains what can be wrong with
> system-supplied rand() functions. He wrote it 20 years ago, and things
> must have improved since then; but I still wouldn't trust a
> system-supplied rand(). He gives code for improving a system rand(),
> also for replacing it by one known to be good. His code is in C of
> course, but is quite short and is easily translated into other languages.
>
> Nick


So? You don't think the system programmers haven't improved in 20
years? Unless you have a specific problem with it, why reinvent the wheel?

In fact, I'll bet that in 20 years even Knuth's random number generator
has been improved upon.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 02:09 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62