summaryrefslogtreecommitdiff
path: root/numlib/rand.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2018-07-11 22:20:14 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2018-07-11 22:20:14 +0200
commit7beb00cd8d28c3d5893ce3db907a828d64afdea9 (patch)
tree395a3dee2fe197b8284dee02c5f527889df78413 /numlib/rand.c
parente2d30e0583c047a4bedf4c8d0c86320f1b3fd8ed (diff)
parenta0442ed58dee48a521ea053083ea967894507898 (diff)
Update upstream source from tag 'upstream/2.0.1+repack'
Update to upstream version '2.0.1+repack' with Debian dir 6edb5dd2df9aca152662fc4a8f72bd6d86f8552e
Diffstat (limited to 'numlib/rand.c')
-rwxr-xr-xnumlib/rand.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/numlib/rand.c b/numlib/rand.c
index 9e58de3..e2fdfdf 100755
--- a/numlib/rand.c
+++ b/numlib/rand.c
@@ -39,12 +39,18 @@ double ranno(void) {
return rand32_th(NULL, 0) / 4294967295.0;
}
-/* Return a random double in the range min to max */
+/* Return a uniform random double in the range min to max */
double
d_rand(double min, double max) {
return d_rand_th(NULL, min, max);
}
+/* Return a squared distribution random double in the range min to max */
+double
+d2_rand(double min, double max) {
+ return d2_rand_th(NULL, min, max);
+}
+
/* Return a random integer in the range min to max inclusive */
int
i_rand(int min, int max) {
@@ -81,6 +87,7 @@ unsigned int seed /* Optional seed. Non-zero re-initialized with that seed */
p = &g_rand;
if (seed != 0) {
+//printf("~1 rand 0x%x seed 0x%x\n",p,seed);
p->pvs_inited = 0;
p->ran = seed;
}
@@ -98,21 +105,29 @@ unsigned int seed /* Optional seed. Non-zero re-initialized with that seed */
p->last = p->pvs[i]; /* Value generated */
p->pvs[i] = p->ran = PSRAND32(p->ran); /* New value */
+//printf("~1 rand 0x%x ret 0x%x\n",p,p->last-1);
return p->last-1;
}
/* return a random number between 0.0 and 1.0 */
/* based on rand32 */
double ranno_th(rand_state *p) {
- return rand32_th(NULL, 0) / 4294967295.0;
+ return rand32_th(p, 0) / 4294967295.0;
}
-/* Return a random double in the range min to max */
+/* Return a uniform random double in the range min to max */
double
d_rand_th(rand_state *p, double min, double max) {
return min + (max - min) * ranno_th(p);
}
+/* Return a squared distribution random double in the range min to max */
+double
+d2_rand_th(rand_state *p, double min, double max) {
+ double val = ranno_th(p);
+ return min + (max - min) * val * val;
+}
+
/* Return a random integer in the range min to max inclusive */
int
i_rand_th(rand_state *p, int min, int max) {