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
crosstabN(text sql)
==================================================================
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
Synopsis
-normal_rand(int numvals, float8 mean, float8 stddev, int seed)
+normal_rand(int numvals, float8 mean, float8 stddev)
Inputs
stddev
the standard deviation of the normal distribution of values
- seed
- a seed value for the pseudo-random number generator
-
Outputs
Returns setof float8, where the returned set of random values are normally
Example usage
test=# SELECT * FROM
- test=# normal_rand(1000, 5, 3, EXTRACT(SECONDS FROM CURRENT_TIME(0))::int);
+ test=# normal_rand(1000, 5, 3);
normal_rand
----------------------
1.56556322244898
-- normal_rand()
-- 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
-----
250
-- normal_rand()
-- 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()
* normal_rand - return requested number of random values
* with a Gaussian (Normal) distribution.
*
- * inputs are int numvals, float8 lower_bound, and float8 upper_bound
- * returns float8
+ * inputs are int numvals, float8 mean, and float8 stddev
+ * returns setof float8
*/
PG_FUNCTION_INFO_V1(normal_rand);
Datum
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);
}
-- Adjust this setting to control where the objects get created.
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
AS 'MODULE_PATHNAME','normal_rand'
LANGUAGE 'C' VOLATILE STRICT;