-/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2007-2014. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
+ * under the terms of the license (GNU LGPL) which comes with this package. */
#include "surf/random_mgr.h"
#include "xbt/sysdep.h"
-#include "simgrid_config.h" /*_XBT_WIN32*/
+#include "internal_config.h" /*_XBT_WIN32*/
+#include <math.h>
+#include <stdlib.h>
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(random, surf, "Random part of surf");
#ifdef _XBT_WIN32
} ieee_nan;
};
-#define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent. */
+#define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent. */
double drand48(void);
return 0;
}
-int _drand48_iterate(unsigned short int xsubi[3], struct drand48_data *buffer)
+int _drand48_iterate(unsigned short int xsubi[3],
+ struct drand48_data *buffer)
{
uint64_t X;
uint64_t result;
{
double result;
- (void) _erand48_r(__libc_drand48_data.__x, &__libc_drand48_data, &result);
+ (void) _erand48_r(__libc_drand48_data.__x, &__libc_drand48_data,
+ &result);
return result;
}
#endif
-static double custom_random(Generator generator, long int *seed)
+static double custom_random(e_random_generator_t generator, long int *seed)
{
switch (generator) {
return drand48();
case RAND:
return (double) rand_r((unsigned int *) seed) / RAND_MAX;
+ case RNGSTREAM :
+ XBT_INFO("Seen RNGSTREAM");
+ return 0.0;
default:
return drand48();
}
if (random->std == 0)
return random->mean * (random->max - random->min) + random->min;
- a =
- random->mean * (random->mean * (1 - random->mean) /
- (random->std * random->std) - 1);
- b =
- (1 -
- random->mean) * (random->mean * (1 -
- random->mean) / (random->std *
- random->std) - 1);
+ a = random->mean * (random->mean * (1 - random->mean) /
+ (random->std * random->std) - 1);
+ b = (1 -
+ random->mean) * (random->mean * (1 -
+ random->mean) / (random->std *
+ random->std) - 1);
alpha = a + b;
if (a <= 1. || b <= 1.)
return X * (random->max - random->min) + random->min;
}
-random_data_t random_new(Generator generator, long int seed,
+random_data_t random_new(e_random_generator_t generator, long int seed,
double min, double max, double mean, double std)
{
random_data_t random = xbt_new0(s_random_data_t, 1);
/* Check user stupidities */
if (max < min)
- THROW2(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
+ THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
if (mean < min)
- THROW2(arg_error, 0, "random->mean < random->min (%f < %f)", mean, min);
+ THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
+ min);
if (mean > max)
- THROW2(arg_error, 0, "random->mean > random->max (%f > %f)", mean, max);
+ THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
+ max);
/* normalize the mean and standard deviation before storing */
random->mean = (mean - min) / (max - min);
random->std = std / (max - min);
if (random->mean * (1 - random->mean) < random->std * random->std)
- THROW2(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
+ THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
random->mean, random->std);
return random;