Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tprest
committed
Mar 21, 2015
1 parent
2cd89e1
commit 3ff636f
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#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; | ||
ZZ SqNorm0, Ratio; | ||
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; | ||
} | ||
|