aboutsummaryrefslogtreecommitdiff
path: root/numalgo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'numalgo.cpp')
-rw-r--r--numalgo.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/numalgo.cpp b/numalgo.cpp
index c3bfa1b..38184b1 100644
--- a/numalgo.cpp
+++ b/numalgo.cpp
@@ -4,6 +4,15 @@
using namespace std;
+int64_t gcd(int64_t a,int64_t b){
+ while(true){
+ if(a==0)return b;
+ if(b==0)return a;
+ if(abs(a)>abs(b))a%=b;
+ else b%=a;
+ }
+}
+
Bigint gcd(Bigint a,Bigint b){
while(true){
if(a==0)return b;
@@ -113,7 +122,7 @@ int ilog2(uint64_t i){
return l;
}
-Bigint cryptrandom_big(const Bigint &bound){
+Bigint bigrandom(Rng &rng,const Bigint &bound){
const int blocksize=32;
int btc=bound.bitcount();
int nblocks=btc/blocksize,rest=btc%blocksize;
@@ -121,11 +130,11 @@ Bigint cryptrandom_big(const Bigint &bound){
Bigint res;
for(int i=0;i<nblocks;i++){
if(i!=0)res<<=blocksize;
- res+=arc4random_uniform((uint32_t)(((uint64_t)1<<blocksize)-1)); //make sure we don't shift out of our int
+ res+=rng.get_uniform((uint32_t)(((uint64_t)1<<blocksize)-1)); //make sure we don't shift out of our int
}
if(rest){
res<<=rest;
- res+=arc4random_uniform((uint32_t)1<<rest);
+ res+=rng.get_uniform((uint32_t)1<<rest);
}
if(res<=bound)return res;
}