micro365/getNewPrompt.mjs

32 lines
748 B
JavaScript
Raw Normal View History

2023-08-11 12:40:19 +00:00
import logger from "./logger.mjs"
2023-08-13 13:00:24 +00:00
import { getAcceptablePrompts } from "./database-calls/db.mjs"
2023-08-12 09:43:37 +00:00
import config from "./config.mjs"
2023-08-11 22:18:09 +00:00
2023-08-12 09:43:37 +00:00
export default async function getNewPrompt() {
logger.trace("getNewPrompt called")
2023-08-11 22:18:09 +00:00
2023-08-08 14:52:17 +00:00
const getBiasedRng = (min, max, bias, influence) => {
const random = Math.random() * (max - min) + min
const mix = Math.random() * influence
return random * (1 - mix) + bias * mix
}
2023-08-06 22:24:49 +00:00
const randomEntry = (array) => {
2023-08-12 09:43:37 +00:00
const random = getBiasedRng(0, 1, config.rarityBias, 1)
2023-08-06 22:59:24 +00:00
const mix = Math.random()
2023-08-06 22:24:49 +00:00
return array[
parseInt(
array.length * random
)
]
}
2023-08-06 22:59:24 +00:00
2023-08-11 22:18:09 +00:00
return randomEntry(await getAcceptablePrompts())
2023-08-06 22:24:49 +00:00
}
2023-08-06 22:24:49 +00:00