Switch random_number() to always use the best entropy source for internal
client purposes. The RANDOM_SOURCE setting now only affects the $rand() scripting function. git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@357 13b04d17-f746-0410-82c6-800466cd88b0
This commit is contained in:
@@ -1347,13 +1347,31 @@ BUILT_IN_FUNCTION(function_mid, word)
|
||||
*/
|
||||
BUILT_IN_FUNCTION(function_rand, word)
|
||||
{
|
||||
long tempin;
|
||||
int result;
|
||||
long tempin;
|
||||
unsigned long rand_n;
|
||||
int result;
|
||||
|
||||
GET_INT_ARG(tempin, word);
|
||||
if (tempin == 0)
|
||||
tempin = (unsigned long) -1; /* This is cheating. :P */
|
||||
result = random_number(0L) % tempin;
|
||||
|
||||
switch (get_int_var(RANDOM_SOURCE_VAR))
|
||||
{
|
||||
case 0:
|
||||
default:
|
||||
rand_n = randd(0);
|
||||
break;
|
||||
case 1:
|
||||
rand_n = randm(0);
|
||||
break;
|
||||
case 2:
|
||||
rand_n = randt(0);
|
||||
break;
|
||||
}
|
||||
|
||||
if (tempin)
|
||||
result = rand_n % tempin;
|
||||
else
|
||||
result = rand_n;
|
||||
|
||||
RETURN_INT(result);
|
||||
}
|
||||
|
||||
@@ -1365,7 +1383,9 @@ BUILT_IN_FUNCTION(function_rand, word)
|
||||
*/
|
||||
BUILT_IN_FUNCTION(function_srand, word)
|
||||
{
|
||||
random_number((long) now);
|
||||
/* randd() and randt() do not accept seeding */
|
||||
randm((long)now);
|
||||
|
||||
RETURN_EMPTY;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user