Published
Edited
May 7, 2019
1 star
Insert cell
md`# MurmurHash3 test`
Insert cell
murmurHash3 = require("murmurhash3js@3.0.1/murmurhash3js.min.js")
Insert cell
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
Insert cell
function makeid(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
Insert cell
makeid(getRandomArbitrary(1, 40));
Insert cell
function generateUsers(n) {
let users = [];
for (var i = 0; i < n; i++) {
users.push(makeid(getRandomArbitrary(1, 40)));
}
return users;
}
Insert cell
generateUsers(1000);
Insert cell
murmurHash3.x86.hash32("I will not buy this record, it is scratched.");
Insert cell
murmurHash3.x86.hash32("I will not buy this recortchd.");
Insert cell
function generateHashes(n) {
return generateUsers(n).map(u => Math.abs(murmurHash3.x86.hash32(u) % 100))
};
Insert cell
Math.max.apply(Math, generateHashes(1000));
Insert cell
Math.min.apply(Math, generateHashes(1000));
Insert cell
import {chart as histogram1}
with {hashes as data}
from "@d3/histogram"
Insert cell
function split(proportion, n) {
let hashes = generateHashes(n);
var a = 0;
var b = 0;
for (var i = 0; i < hashes.length; i++) {
if (hashes[i] < proportion)
a++;
else
b++;
}
var aresult = a / hashes.length * 100;
var bresult = b / hashes.length * 100;
return `
${hashes.length},${proportion}/${100-proportion},${aresult},${bresult},${Math.abs(aresult - proportion)}}`;
}
Insert cell
histogram1
Insert cell
function evaluate(n) {
let results = "";
results += split(8, n);
results += split(25, n);
results += split(50, n);
return results;
}
Insert cell
USERS = 1000
Insert cell
evaluate(10000);
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more