From 02132f55c29f15dcc1fe0b52158c31e11c21ae5b Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 11 Feb 2003 23:19:47 +0100 Subject: [PATCH] backporting Peter's fix for better RAND() initialization from 4.0 sql/sql_class.cc: backporting Peter's fix for better RAND() initialization from 4.0 to see what it does try perl -e 'while($N=shift) { printf "N=%-10d",$N; @b=@c=(); for (1..$N) { @a=split(" ",`mysql -BNe "select rand(), rand(), rand(), rand()"`); for(0..3) { $b[$_]+=$a[$_]; $c[$_]+=$a[$_]*$a[$_]; }} for (0..3) { printf "%15.14f ",($c[$_]-$b[$_]*$b[$_]/$N)/$N } print "\n" }' 10 10 10 100 100 10 100 1000 before and after the fix --- sql/sql_class.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index eada94e3d40..319bc87ad8d 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -156,7 +156,7 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0), */ { pthread_mutex_lock(&LOCK_thread_count); - ulong tmp=(ulong) (rnd(&sql_rand) * 3000000); + ulong tmp=(ulong) (rnd(&sql_rand) * ((ulong)~0L)); randominit(&rand, tmp + (ulong) start_time, tmp + (ulong) thread_id); pthread_mutex_unlock(&LOCK_thread_count);