aboutsummaryrefslogtreecommitdiff
path: root/math/slalib/rtl_random.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
commitfa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch)
treebdda434976bc09c864f2e4fa6f16ba1952b1e555 /math/slalib/rtl_random.c
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'math/slalib/rtl_random.c')
-rw-r--r--math/slalib/rtl_random.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/math/slalib/rtl_random.c b/math/slalib/rtl_random.c
new file mode 100644
index 00000000..a8730c0c
--- /dev/null
+++ b/math/slalib/rtl_random.c
@@ -0,0 +1,33 @@
+#include <stdlib.h>
+
+float
+random_ ( int *iseed )
+/*
+** - - - - - - -
+** r a n d o m
+** - - - - - - -
+**
+** Generate pseudo-random real number in the range 0 <= x < 1.
+**
+** (single precision)
+**
+** This function is designed to replace the Fortran->C interface routine
+** random(3f) on systems which do not have this library (for example Linux)
+**
+** Fortran call: X = RANDOM(ISEED)
+**
+** Given:
+** iseed int seed value
+**
+** If iseed !=0 random-number generator is initialised and first number
+** is returned.
+** iseed == 0 next number in the sequence is returned
+**
+** B.K.McIlwrath Starlink 12 January 1996
+*/
+{
+ if( *iseed != 0 )
+ srand(*iseed);
+
+ return (float) rand() / (float) RAND_MAX;
+}