Skip to content

Instantly share code, notes, and snippets.

@typeofweb
Created March 28, 2013 09:31
Show Gist options
  • Save typeofweb/5261932 to your computer and use it in GitHub Desktop.
Save typeofweb/5261932 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <bitset>
using std::cout;
using std::vector;
using std::bitset;
void generator_lin (unsigned a, unsigned c, unsigned m, unsigned x0) {
vector <unsigned> przedzialy (10, 0);
unsigned xn = x0;
for (unsigned i = 0; i < 100000; ++i) {
xn = (a * xn + c) % m;
++przedzialy[static_cast<int>(xn / (double)m * 10)];
}
for (auto i = przedzialy.begin(); i != przedzialy.end(); ++i) {
cout << *i << " ";
}
cout << "\n";
}
void generator_przesuwny (bitset<7> b, unsigned p, unsigned q, unsigned m) {
bitset<31> bn(b.to_string(), 0);
for (unsigned i = p; i < bn.size(); ++i) {
bn[i] = bn[i - p] ^ bn[i - q];
}
vector <unsigned> przedzialy (10, 0);
for (unsigned i = 0; i < 100000; ++i) {
unsigned liczba = bn.to_ullong();
++przedzialy[static_cast<int>(liczba / (double)m * 10)];
bn = bn >> 1;
bn[bn.size() - 1] = bn[bn.size() - 1 - p] ^ bn[bn.size() - 1 - q];
}
for (auto i = przedzialy.begin(); i != przedzialy.end(); ++i) {
cout << *i << " ";
}
}
int main () {
// generator_lin(69069, 1, ( (1<<31) - 1), 15);
bitset<7> b("0111011");
generator_przesuwny(b, 7, 3, ((1<<31) - 1));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment