aboutsummaryrefslogtreecommitdiff
path: root/src/slalib/rtl_random.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/slalib/rtl_random.c')
-rw-r--r--src/slalib/rtl_random.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/slalib/rtl_random.c b/src/slalib/rtl_random.c
new file mode 100644
index 0000000..a8730c0
--- /dev/null
+++ b/src/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;
+}