CYBERTEC PostgreSQL Logo

Making random() deterministic - random generator in PostgreSQL

12.2013 / Category: / Tags: |

Basically the idea of a random generator is to generate random data
– ideally a lot of random and non-deterministic data. However, sometimes it is necessary to be able to reproduce a random sequence of numbers. Why would anybody want to do that? Well, what if you are running a simulation model? Or what if you want to compare results coming from different servers? In all those cases it is necessary to reset the random generator to restart a certain value.

To make sure the random generator starts all over again, you have to set a seed just like shown in the following listing:

As you can see, the next random value is the same all the time.

This is highly important if you want to control the behavior of your random number generation process (just like you would do it in any programming language).

If you're also interested in PostgreSQL performance and logging, check out our WAL blog spot.

Leave a Reply

Your email address will not be published. Required fields are marked *

CYBERTEC Logo white
Get the newest PostgreSQL Info & Tools


    This site is protected by reCAPTCHA and the Google Privacy Policy & Terms of Service apply.

    ©
    2024
    CYBERTEC PostgreSQL International GmbH
    phone-handsetmagnifiercrosscross-circle
    linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram