Close

PL/SQL package for 64-bit xoshiro/xoroshiro pseudorandom number generators

Continuing in the path of previous two posts, the package below supports all of the xoshiro/xoroshiro algorithms returning 64-bit values. The numbers in the names refer to the size of the state array that each method operates on. Using each of them follows the same pattern: For example… SQL> BEGIN 2 xoshiro.set_mode(‘xoroshiro128++’); 3 xoshiro.set_state(xoshiro.seed_tab(12345, 67890));…

Using Object Types: constructors

When an object type is instantiated (i.e. assigned a non-null value) it will execute initialization code. This initialization code is called a CONSTRUCTOR function. Every object type includes an implicit constructor which simply assigns values to the object attributes according to the values provided in the object assignment. For example: CREATE OR REPLACE TYPE simpleobject…

Nifty math trick with hierarchical query

Using the algorithm discovered by David Bailey, Peter Borwein, and Simon Plouffe, you can easily generate values of pi with a simple recursive query… SQL> SELECT d, to_char(bbp, rpad(‘0.’,55, ‘9’)) bbp,   2    TO_CHAR(   3       SUM(bbp) OVER (ORDER BY d),   4       ‘9.’ || RPAD(‘9’, d – 1, ‘9’)   5    ) pi  …