You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The IB_UDF_rand function, as stated on the Language
Reference manual, is seeded with the current time. This
is ok if you call the function once in a while, but if you're
executing an SQL script that calls the function
continuously (for instance, if you have a BEFORE INSERT
trigger that uses the function for inserting random
values on a field and you're inserting many rows), it
returns often the same value.
I think this behaviour is caused by the seed being
practically constant during fast operations. Think for
example at a series of INSERTs in an SQL script being
executed in a single transaction, every row is processed
very fast and the system time used for seeding the
random function is often the same. This results in
constant values being generated by the random
function, at least for a certain consecutive number of
inserted rows (until the time changes).
In my opinion, a random number generator should be
initialized only once, otherwise its usefulness is almost
lost because it becomes a mere number transformation
routine (instead of a pseudo-random sequence
generator).
Franco.
The text was updated successfully, but these errors were encountered:
Our new script is ib_udf2.sql
Frank separated the function in two independent UDFs, srand
and rand:
- The first time you call srand, it will set the seed from
the system time and will return the first pseudo random number.
- From that point you continue calling rand and it will use
the same seed.
Submitted by: sidbozzy (sidbozzy)
Assigned to: Frank Schlottmann-Goedde (fsg)
SFID: 882075#
Submitted By: sidbozzy
The IB_UDF_rand function, as stated on the Language
Reference manual, is seeded with the current time. This
is ok if you call the function once in a while, but if you're
executing an SQL script that calls the function
continuously (for instance, if you have a BEFORE INSERT
trigger that uses the function for inserting random
values on a field and you're inserting many rows), it
returns often the same value.
I think this behaviour is caused by the seed being
practically constant during fast operations. Think for
example at a series of INSERTs in an SQL script being
executed in a single transaction, every row is processed
very fast and the system time used for seeding the
random function is often the same. This results in
constant values being generated by the random
function, at least for a certain consecutive number of
inserted rows (until the time changes).
In my opinion, a random number generator should be
initialized only once, otherwise its usefulness is almost
lost because it becomes a mere number transformation
routine (instead of a pseudo-random sequence
generator).
Franco.
The text was updated successfully, but these errors were encountered: