-
Notifications
You must be signed in to change notification settings - Fork 2
/
random.cpp
64 lines (49 loc) · 1.07 KB
/
random.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <stdlib.h>
#include"point.h"
#ifndef _LIB_GMP
#include <gmpxx.h>
#endif
#define GMPInt mpz_class
GMPInt maxgmp;
BigInt maxglb=0;
gmp_randclass r (gmp_randinit_mt);
void init_random_number_generator(const int seed, BigInt max)
{
maxglb=max;
// maxgmp.mpz_set_str("123");
maxgmp.set_str(STR(max), 10);
// mpz_set_str (&maxgmp, "1000", base);
r.seed(seed);
}
BigInt random_number(const BigInt max)
{
if (max != maxglb)
{
fprintf(stderr, "Erro max != maxglb\n");
exit(1);
}
GMPInt temp = r.get_z_range(maxgmp);
//printf("random = %s\n", temp.get_str(10).c_str());
#ifdef _LIB_GMP
return temp;
#else
BigInt tmp(temp.get_str(10).c_str());
// printf("random = %s\n", STR(tmp));
return tmp;
#endif
}
#ifdef _TEST_MAIN
int main(int argc, char *argv[])
{
#ifndef _LIB_GMP
printf("Using ttmath\n");
#else
printf("Using gmp\n");
#endif
BigInt max=100;
init_random_number_generator(0, max);
for(int i=0; i<10; i++) printf("Random = %s\n", STR(random_number(max)));
return 0;
}
#endif