Separate Studio 2 source and canvas and apply size and seed choices
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
let previous
|
||||
export function randomSeed() {
|
||||
const bytes = new Uint32Array(1)
|
||||
globalThis.crypto.getRandomValues(bytes)
|
||||
let seed = 2 + bytes[0] % 2147483646
|
||||
if (seed === previous) seed = seed === 2147483647 ? 2 : seed + 1
|
||||
previous = seed
|
||||
return seed
|
||||
}
|
||||
export function queueSeeds(settings = {}, count = 1) {
|
||||
if (settings.seedMode === 'locked') {
|
||||
const seed=Number(settings.seed)
|
||||
if (!Number.isInteger(seed) || seed<0 || seed>2147483647) throw Object.assign(new Error('Invalid seed.'),{statusCode:400})
|
||||
return Array(count).fill(seed)
|
||||
}
|
||||
return Array.from({length:count},()=>randomSeed())
|
||||
}
|
||||
Reference in New Issue
Block a user