Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IB_UDF_rand misbehaviour/enhancement [CORE722] #1097

Closed
firebird-automations opened this issue Jan 22, 2004 · 3 comments
Closed

IB_UDF_rand misbehaviour/enhancement [CORE722] #1097

firebird-automations opened this issue Jan 22, 2004 · 3 comments

Comments

@firebird-automations
Copy link
Collaborator

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.

@firebird-automations
Copy link
Collaborator Author

Commented by: Alice F. Bird (firebirds)

Date: 2005-05-31 04:57
Sender: robocop
Logged In: YES
user_id=62823

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.

@firebird-automations
Copy link
Collaborator Author

Commented by: Alice F. Bird (firebirds)

Date: 2005-05-30 16:52
Sender: dimitr
Logged In: YES
user_id=61270

Claudio, your opinion?

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

Workflow: jira [ 10746 ] => Firebird [ 15139 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant