Skip to content

Instantly share code, notes, and snippets.

@likai24
Created March 19, 2018 05:34
Show Gist options
  • Save likai24/57c4c5758961abe0d843b0ea43db1c69 to your computer and use it in GitHub Desktop.
Save likai24/57c4c5758961abe0d843b0ea43db1c69 to your computer and use it in GitHub Desktop.
Random Collision Test
const crypto = require('crypto');
var count = 0;
var total = 0;
function getDt(){
var dt = (new Date()).toString()
var p = /\d+:\d+:\d+/.exec(dt);
if(p.length > 0){
return dt = p[0];
}
}
function cryptoR(){
let num = crypto.randomBytes(1, function(err, buffer) {
var num = buffer.toString('hex');
num = parseInt(num, 16);
let dt = getDt();
if(num > 240){
total += 1;
console.log(`"${dt}", num: "${num}" try: "${count}" total:"${total}"\n`);
count = 0;
}else{
console.log('\n');
count += 1;
}
});
}
function random(){
let num = Math.random();
let dt = getDt();
if(num > 0.95){
total += 1;
console.log(`"${dt}", num: "${parseInt(num*100)/100}" try: "${count}" total:"${total}"\n`);
count = 0;
}else{
console.log('\n');
count += 1;
}
}
setInterval(cryptoR, 2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment