Public
Edited
Jun 23, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
bits = {
const allBits = initialBits.slice();
const newBits = [];
for (let i=initialBits.length-1; i < numberOfPoints; i++) {
allBits.push(nextBit(i, allBits));
newBits.push(nextBit(i, allBits));
}
return allBits
}
Insert cell
nextBit = (k, bits) => {
return bits[k-p] ^ bits[k-p+q]
}
Insert cell
Insert cell
Insert cell
naturalNumbers = {
const naturalNumbers = [];
for (let i=initialBits.length-1; i < bits.length; i++) {
let naturalNumber = 0;
for (let j=0; j < 10; j++) {
naturalNumber += bits[i-j]*2**j
}
naturalNumbers.push(naturalNumber)
}
return naturalNumbers
}
Insert cell
Insert cell
rationalNumbers = naturalNumbers.map((num) => num/2**10)
Insert cell
rationalRange = [d3.min(rationalNumbers), d3.max(rationalNumbers)]
Insert cell
Insert cell
findPeriod(bits).split(",").length
Insert cell
Insert cell
randomBits = {
const rnd = new mt.default(parseInt(1010101010, 2));
const generated = [];
for (let i = 0; i < numberOfPoints-9; i++) generated.push(rnd.random() % 360);
return generated;
}
Insert cell
Insert cell
// generating points for plot
plotPoints = {
const points = [];
for(let i=0; i<parseInt(rationalNumbers.length/2); i++) {
points.push([rationalNumbers[i], rationalNumbers[rationalNumbers.length-1-i]])
}
return points
}
Insert cell
Insert cell
Insert cell
q = 3
Insert cell
p = 9
Insert cell
initialBits = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]
Insert cell
randomPoints = {
const points = [];
for(let i=0; i<parseInt(randomBits.length/2); i++) {
points.push([randomBits[i], randomBits[randomBits.length-1-i]])
}
return points
}
Insert cell
mt = await import("https://esm.sh/mersennetwister@0.2.3")
Insert cell
numPointsPlot = randomPoints.length
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