Commit c472b836 authored by Tom Lane's avatar Tom Lane

With Joe Conway's concurrence, remove srandom() call from normal_rand().

This was the last piece of code that took it upon itself to reset the
random number sequence --- now we only have srandom() in postmaster start,
backend start, and explicit setseed() operations.
parent 94a13b8a
...@@ -48,7 +48,7 @@ Installation: ...@@ -48,7 +48,7 @@ Installation:
installs following functions into database template1: installs following functions into database template1:
normal_rand(int numvals, float8 mean, float8 stddev, int seed) normal_rand(int numvals, float8 mean, float8 stddev)
- returns a set of normally distributed float8 values - returns a set of normally distributed float8 values
crosstabN(text sql) crosstabN(text sql)
...@@ -74,12 +74,12 @@ Documentation ...@@ -74,12 +74,12 @@ Documentation
================================================================== ==================================================================
Name Name
normal_rand(int, float8, float8, int) - returns a set of normally normal_rand(int, float8, float8) - returns a set of normally
distributed float8 values distributed float8 values
Synopsis Synopsis
normal_rand(int numvals, float8 mean, float8 stddev, int seed) normal_rand(int numvals, float8 mean, float8 stddev)
Inputs Inputs
...@@ -92,9 +92,6 @@ Inputs ...@@ -92,9 +92,6 @@ Inputs
stddev stddev
the standard deviation of the normal distribution of values the standard deviation of the normal distribution of values
seed
a seed value for the pseudo-random number generator
Outputs Outputs
Returns setof float8, where the returned set of random values are normally Returns setof float8, where the returned set of random values are normally
...@@ -103,7 +100,7 @@ Outputs ...@@ -103,7 +100,7 @@ Outputs
Example usage Example usage
test=# SELECT * FROM test=# SELECT * FROM
test=# normal_rand(1000, 5, 3, EXTRACT(SECONDS FROM CURRENT_TIME(0))::int); test=# normal_rand(1000, 5, 3);
normal_rand normal_rand
---------------------- ----------------------
1.56556322244898 1.56556322244898
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
-- normal_rand() -- normal_rand()
-- no easy way to do this for regression testing -- no easy way to do this for regression testing
-- --
SELECT avg(normal_rand)::int FROM normal_rand(100, 250, 0.2, EXTRACT(SECONDS FROM CURRENT_TIME(0))::int); SELECT avg(normal_rand)::int FROM normal_rand(100, 250, 0.2);
avg avg
----- -----
250 250
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
-- normal_rand() -- normal_rand()
-- no easy way to do this for regression testing -- no easy way to do this for regression testing
-- --
SELECT avg(normal_rand)::int FROM normal_rand(100, 250, 0.2, EXTRACT(SECONDS FROM CURRENT_TIME(0))::int); SELECT avg(normal_rand)::int FROM normal_rand(100, 250, 0.2);
-- --
-- crosstab() -- crosstab()
......
...@@ -165,8 +165,8 @@ typedef struct crosstab_hashent ...@@ -165,8 +165,8 @@ typedef struct crosstab_hashent
* normal_rand - return requested number of random values * normal_rand - return requested number of random values
* with a Gaussian (Normal) distribution. * with a Gaussian (Normal) distribution.
* *
* inputs are int numvals, float8 lower_bound, and float8 upper_bound * inputs are int numvals, float8 mean, and float8 stddev
* returns float8 * returns setof float8
*/ */
PG_FUNCTION_INFO_V1(normal_rand); PG_FUNCTION_INFO_V1(normal_rand);
Datum Datum
...@@ -213,12 +213,6 @@ normal_rand(PG_FUNCTION_ARGS) ...@@ -213,12 +213,6 @@ normal_rand(PG_FUNCTION_ARGS)
funcctx->user_fctx = fctx; funcctx->user_fctx = fctx;
/*
* we might actually get passed a negative number, but for this
* purpose it doesn't matter, just cast it as an unsigned value
*/
srandom(PG_GETARG_UINT32(3));
MemoryContextSwitchTo(oldcontext); MemoryContextSwitchTo(oldcontext);
} }
......
-- Adjust this setting to control where the objects get created. -- Adjust this setting to control where the objects get created.
SET search_path = public; SET search_path = public;
CREATE OR REPLACE FUNCTION normal_rand(int4, float8, float8, int4) CREATE OR REPLACE FUNCTION normal_rand(int4, float8, float8)
RETURNS setof float8 RETURNS setof float8
AS 'MODULE_PATHNAME','normal_rand' AS 'MODULE_PATHNAME','normal_rand'
LANGUAGE 'C' VOLATILE STRICT; LANGUAGE 'C' VOLATILE STRICT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment