1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-16 13:38:02 +00:00

Add Set Seed For Random Number Generator as a postgres til

This commit is contained in:
jbranchaud
2016-02-03 19:38:05 -06:00
parent 1d5c5a53a1
commit 6764eded72
2 changed files with 43 additions and 0 deletions

View File

@@ -169,6 +169,7 @@ _322 TILs and counting..._
- [Restarting Sequences When Truncating Tables](postgres/restarting-sequences-when-truncating-tables.md) - [Restarting Sequences When Truncating Tables](postgres/restarting-sequences-when-truncating-tables.md)
- [Send A Command To psql](postgres/send-a-command-to-psql.md) - [Send A Command To psql](postgres/send-a-command-to-psql.md)
- [Set Inclusion With hstore](postgres/set-inclusion-with-hstore.md) - [Set Inclusion With hstore](postgres/set-inclusion-with-hstore.md)
- [Set Seed For Random Number Generator](postgres/set-seed-for-random-number-generator.md)
- [Sleeping](postgres/sleeping.md) - [Sleeping](postgres/sleeping.md)
- [Special Math Operators](postgres/special-math-operators.md) - [Special Math Operators](postgres/special-math-operators.md)
- [String Contains Another String](postgres/string-contains-another-string.md) - [String Contains Another String](postgres/string-contains-another-string.md)

View File

@@ -0,0 +1,42 @@
# Set Seed For Random Number Generator
In PostgreSQL, the internal seed for the random number generator is a
run-time configuration parameter. This `seed` parameter can be set to a
particular seed in order to get some determinism from functions that utilize
the random number generator. The seed needs to be something between `0` and
`1`.
```sql
> set seed to 0.1234;
SET
> select random();
random
-------------------
0.397731185890734
> select random();
random
------------------
0.39575699577108
(1 row)
> set seed to 0.1234;
SET
> select random();
random
-------------------
0.397731185890734
> select random();
random
------------------
0.39575699577108
```
The seed can also be configured with the `setseed()` function.
See [the PostgreSQL
docs](http://www.postgresql.org/docs/8.3/static/sql-set.html) for more
details.