fix: randomFloatFrom now correctly stays in range

This commit is contained in:
sthag 2026-04-04 09:59:43 +02:00
parent 19577eca8c
commit a67a36decb

View file

@ -1,3 +1,5 @@
/* jshint strict: false */
// TODO: Inhalte angleichen nach Zusammenfassung von app.js und function.js.
// Benennung und Beschreibungen verbessern.
@ -424,10 +426,10 @@ function randomIntFrom(min, max, pos = 0) {
return Math.floor((Math.random() * (max - min + 1) + min) / pos) * pos;
}
function randomFloatFrom(min, max, dec = 0) {
function randomFloatFrom(min, max, dec = 1) {
dec = Math.pow(10, dec);
return Math.round((Math.random() * (max - min + 1) + min) * dec) / dec;
return Math.round((Math.random() * (max - min) + min) * dec) / dec;
}
/**