| | |
| | | #include <string.h> |
| | | #include <math.h> |
| | | #include <assert.h> |
| | | #include "unistd.h" |
| | | #include <float.h> |
| | | #include <limits.h> |
| | | #ifdef WIN32 |
| | | #include "utils.h" |
| | | #include "unistd.h" |
| | | #else |
| | | #include <utils.h> |
| | | #include <unistd.h> |
| | | #endif |
| | | #include "utils.h" |
| | | |
| | | #pragma warning(disable: 4996) |
| | | |
| | |
| | | { |
| | | c = next+1; |
| | | } |
| | | if(!next) while ((next = strchr(c, '\\'))) { c = next + 1; } |
| | | c = copy_string(c); |
| | | next = strchr(c, '.'); |
| | | if (next) *next = 0; |
| | |
| | | fgets(&line[curr], readsize, fp); |
| | | curr = strlen(line); |
| | | } |
| | | if(line[curr-1] == '\n') line[curr-1] = '\0'; |
| | | if(line[curr-2] == 0x0d) line[curr-2] = 0x00; |
| | | if(line[curr-1] == 0x0a) line[curr-1] = 0x00; |
| | | |
| | | return line; |
| | | } |
| | |
| | | return max_i; |
| | | } |
| | | |
| | | int int_index(int *a, int val, int n) |
| | | { |
| | | int i; |
| | | for (i = 0; i < n; ++i) { |
| | | if (a[i] == val) return i; |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | int rand_int(int min, int max) |
| | | { |
| | | if (max < min){ |
| | |
| | | max = swap; |
| | | } |
| | | return ((float)rand()/RAND_MAX * (max - min)) + min; |
| | | //return (random_float() * (max - min)) + min; |
| | | } |
| | | |
| | | float rand_scale(float s) |
| | | { |
| | | float scale = rand_uniform(1, s); |
| | | if(rand()%2) return scale; |
| | | float scale = rand_uniform_strong(1, s); |
| | | if(random_gen()%2) return scale; |
| | | return 1./scale; |
| | | } |
| | | |
| | |
| | | return t; |
| | | } |
| | | |
| | | unsigned int random_gen() |
| | | { |
| | | unsigned int rnd = 0; |
| | | #ifdef WIN32 |
| | | rand_s(&rnd); |
| | | #else |
| | | rnd = rand(); |
| | | #endif |
| | | return rnd; |
| | | } |
| | | |
| | | float random_float() |
| | | { |
| | | #ifdef WIN32 |
| | | return ((float)random_gen() / (float)UINT_MAX); |
| | | #else |
| | | return ((float)random_gen() / (float)RAND_MAX); |
| | | #endif |
| | | } |
| | | |
| | | float rand_uniform_strong(float min, float max) |
| | | { |
| | | if (max < min) { |
| | | float swap = min; |
| | | min = max; |
| | | max = swap; |
| | | } |
| | | return (random_float() * (max - min)) + min; |
| | | } |