Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Seitosh
Seitosh
Commits
75436f07
Commit
75436f07
authored
Feb 14, 2019
by
thomas.forbriger
Browse files
croposp [MERGE]: merge improved random number generator from master
parents
9828e6ad
5848b8bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/libs/libtf/tf_gsl_rnd.c
View file @
75436f07
...
...
@@ -31,11 +31,15 @@
* REVISIONS and CHANGES
* - 07/05/2007 V1.0 Thomas Forbriger
* - 13/11/2010 V1.1 changed name of file
* - 14/02/2019 V1.2 change seeding mechanism
* accept default seed value provided through
* environment variable; if no default is set, use
* nanoseconds to seed
*
* ============================================================================
*/
#define TF_TF_GSL_RND_C_CC_VERSION \
"TF_TF_GSL_RND_C_CC V1.
1
"
"TF_TF_GSL_RND_C_CC V1.
2
"
#define TF_TF_GSL_RND_C_CC_CVSID \
"$Id$"
...
...
@@ -55,13 +59,19 @@ int tf_gsl_rng_ugaussian__(doublereal* a, integer* n)
int
i
;
/* set the default type of random number generator
* controlled by the environment variable GSL_RNG_TYPE
*
an
d al
locate a random number generator
*
see
d
v
al
ue can be controlled by GSL_RNG_SEED
*/
gsl_rng_env_setup
();
/* seed the generator with the current time if seed is
* not set on command line */
if
(
gsl_rng_default_seed
==
0
)
{
struct
timespec
tp
;
clock_gettime
(
CLOCK_REALTIME
,
&
tp
);
gsl_rng_default_seed
=
tp
.
tv_nsec
+
time
(
0
)
;
}
const
gsl_rng_type
*
T
=
gsl_rng_default
;
/* and allocate a random number generator */
gsl_rng
*
R
=
gsl_rng_alloc
(
T
);
/* seed the generator with the current time */
gsl_rng_set
(
R
,
time
(
0
));
/* read values from the generator, using the desired distribution */
for
(
i
=
0
;
i
<=*
n
;
++
i
)
{
a
[
i
]
=
(
doublereal
)
gsl_ran_ugaussian
(
R
);
}
...
...
@@ -81,13 +91,19 @@ int tf_gsl_rng_uniform__(doublereal* a, integer* n)
int
i
;
/* set the default type of random number generator
* controlled by the environment variable GSL_RNG_TYPE
*
an
d al
locate a random number generator
*
see
d
v
al
ue can be controlled by GSL_RNG_SEED
*/
gsl_rng_env_setup
();
/* seed the generator with the current time if seed is
* not set on command line */
if
(
gsl_rng_default_seed
==
0
)
{
struct
timespec
tp
;
clock_gettime
(
CLOCK_REALTIME
,
&
tp
);
gsl_rng_default_seed
=
tp
.
tv_nsec
+
time
(
0
)
;
}
const
gsl_rng_type
*
T
=
gsl_rng_default
;
/* and allocate a random number generator */
gsl_rng
*
R
=
gsl_rng_alloc
(
T
);
/* seed the generator with the current time */
gsl_rng_set
(
R
,
time
(
0
));
/* read values from the generator, using the desired distribution */
for
(
i
=
0
;
i
<=*
n
;
++
i
)
{
a
[
i
]
=
(
doublereal
)
gsl_rng_uniform
(
R
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment