Hitmap 1.3
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
my_util.c
Go to the documentation of this file.
1 #define MY_UTIL_MAIN
2 #include "my_util.h"
3 
4 void *my_malloc (int sz)
5 {
6  void *ptr = malloc(sz);
7 
8  if (!ptr){
9  printf ("Error: can't allocate %d bytes\n", sz);
10  exit (0);
11  }
12 #ifdef DEBUG
13  printf("allocating %d bytes to %p\n", sz, ptr);
14 #endif
15 
16  return ptr;
17 }
18 
19 /* generates random integer in [low, high) */
20 int random_integer (int low, int high)
21 {
22  int r;
23  r = ((high-low)*drand48()) + low;
24  if (r==high) r--;
25 
26  return r;
27 }
28 
29 /* generates random double in [low, high) */
30 double random_double (double low, double high)
31 {
32  return ((high-low)*drand48()) + low;
33 }
34 /*
35 MT-LEVEL
36  Safe
37 
38 DESCRIPTION
39  This family of functions generates pseudo-random numbers
40  using the well-known linear congruential algorithm and 48-
41  bit integer arithmetic.
42 
43  Functions drand48() and erand48() return non-negative
44  double-precision floating-point values uniformly distributed
45  over the interval [0.0, 1.0).
46 */
47 
48 
49 int str_to_mem_unit(char *str){
50  int v = 0;
51 
52  while (*str >= '0' && *str <='9'){
53  v = v*10 + *str - '0'; str++;
54  }
55 
56  if (*str == 'm' || *str == 'M'){
57  v *= 1024*1024;
58  }
59  else if (*str == 'k' || *str == 'K'){
60  v *= 1024;
61  }
62 
63  return v;
64 }
int random_integer(int low, int high)
Definition: matrix_io.c:28
#define r(a, b, c)
double random_double(double low, double high)
Definition: matrix_io.c:38
int str_to_mem_unit(char *str)
Definition: matrix_io.c:57
#define v(a, b, c)
void * my_malloc(int sz)
Definition: matrix_io.c:12
double drand48()