MCPcopy Create free account
hub / github.com/cutupdev/Solana-Volume-Bot / randVal

Function randVal

utils/utils.ts:27–47  ·  view source on GitHub ↗
(min: number, max: number, count: number, total: number, isEven: boolean)

Source from the content-addressed store, hash-verified

25
26
27export const randVal = (min: number, max: number, count: number, total: number, isEven: boolean): number[] => {
28
29 const arr: number[] = Array(count).fill(total / count);
30 if (isEven) return arr
31
32 if (max * count < total)
33 throw new Error("Invalid input: max * count must be greater than or equal to total.")
34 if (min * count > total)
35 throw new Error("Invalid input: min * count must be less than or equal to total.")
36 const average = total / count
37 // Randomize pairs of elements
38 for (let i = 0; i < count; i += 2) {
39 // Generate a random adjustment within the range
40 const adjustment = Math.random() * Math.min(max - average, average - min)
41 // Add adjustment to one element and subtract from the other
42 arr[i] += adjustment
43 arr[i + 1] -= adjustment
44 }
45 // if (count % 2) arr.pop()
46 return arr;
47}
48
49
50export const saveDataToFile = (newData: Data[], filePath: string = "data.json") => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected