Public
Edited
May 10, 2023
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
variation = Math.floor(Math.random() * 2) // Could be 0 or 1 (click the ▶ button to flip again)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
hashValue = murmurhashv3(bucketKey, 1)
Insert cell
hashRatio = hashValue / Math.pow(2, 32) // Divide the hash value by the largest possible value, integer 2^32
Insert cell
Insert cell
Insert cell
bucket = parseInt(hashRatio * totalBuckets, 10)
Insert cell
Insert cell
bucket < (totalBuckets/2) ? 'Control' : 'Treatment'
Insert cell
Insert cell
fourAllocations = [
{id: 'Control', rangeEnd: 2500},
{id: 'Treatment A', rangeEnd: 5000},
{id: 'Treatment B', rangeEnd: 7500},
{id: 'Treatment C', rangeEnd: 10000}
]
Insert cell
getVariation = (bucketId, allocations) => {
for (let allocation of allocations) {
if (bucketId < allocation.rangeEnd) {
return allocation.id
}
}
return null
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
getAllocations = (entities) => {
let cummulativePercentage = 0
return entities.map((entity, i) => {
cummulativePercentage += entity.percentage / 100
return {
id: entity.id,
rangeEnd: cummulativePercentage * ((totalBuckets * totalPopulation)/100)
}
})
}
Insert cell
otherAllocations = getAllocations([
{ id: 'Control', percentage: 50 },
{ id: 'Treatment', percentage: 50 }
])
Insert cell
Insert cell
Insert cell
Insert cell
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