-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandom.cc
65 lines (54 loc) · 1.37 KB
/
Random.cc
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
64
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <complex.h>
#include <time.h>
#include <NTL/ZZ.h>
#include <NTL/ZZX.h>
#include <NTL/mat_ZZ.h>
#include <gmp.h>
#include "Random.h"
#include "params.h"
using namespace std;
using namespace NTL;
vec_ZZ RandomVector()
{
vec_ZZ w;
unsigned int i;
w.SetLength(N0);
for(i=0; i<N0; i++)
{
w[i] = conv<ZZ>(rand())%q1;
}
return w;
}
//==============================================================================
//Generates a random polynomial of fixed degree
//==============================================================================
ZZX RandomPoly(const unsigned int degree)
{
unsigned int i;
ZZX f;
f.SetLength(degree+1);
for(i=0; i<=degree; i++)
{
f[i] = rand();
}
return f;
}
//==============================================================================
//Generates a random polynomial of fixed degree and "approximately" fixed squared norm
//==============================================================================
ZZX RandomPolyFixedSqNorm(const ZZ& SqNorm, const unsigned int degree)
{
unsigned int i;
ZZX f;
f.SetLength(degree+1);
RR_t sigma = sqrt( ( (double) conv<double>(SqNorm)/(degree+1) ) );
for(i=0; i<=degree; i++)
{
f[i] = conv<ZZ>(Sample3(sigma));
}
f[degree] |= 1;
return f;
}