lemon
lemon

Reputation: 25

Using Oracle's CREATE SEQUENCE as secure random

I was wondering if Oracle's CREATE SEQUENCE with NOORDER statement (enabled by default) could be used as a secure random number generator ? I mean, is it really random or it could be predicted ?

I couldn't find doc regarding to this spec.

Thanks in advance. lemon

Upvotes: 0

Views: 522

Answers (1)

Justin Cave
Justin Cave

Reputation: 231661

No. If you want random numbers, use the dbms_crypto package.

A sequence with NOORDER specified will still give sequential, ordered numbers in a non-RAC system. If you are using RAC, however, each node will have a separate cache of values and one node will be generating values that are greater than the other nodes at the same time. For example, if you have a 3 node cluster and a sequence with a cache of 20, node 1 would cache the values 1-20, node 2 would cache the values 21-40, and node 3 would cache the values 41-60. If a session on node 3 requested the nextval, it would get 41. Then, if another session on node 1 requested the nextval, it would get the value 1. The next request on node 3 would get 42, the next request on node 1 would get 2, the next request on node 2 would get 21. And, of course, once each node exhausted its cache, it would cache the next 20 values. If one node persistently gets more nextval requests, it can get much further ahead of the nextval on the other nodes.

Upvotes: 2

Related Questions