mirror of
https://github.com/graphql-hive/console
synced 2026-04-21 14:37:17 +00:00
9 lines
284 B
TypeScript
9 lines
284 B
TypeScript
export function randomSampling(sampleRate: number) {
|
|
if (sampleRate > 1 || sampleRate < 0) {
|
|
throw new Error(`Expected usage.sampleRate to be 0 <= x <= 1, received ${sampleRate}`);
|
|
}
|
|
|
|
return function shouldInclude(): boolean {
|
|
return Math.random() <= sampleRate;
|
|
};
|
|
}
|