I did some rough math, with the current formula being used in /apps/openmw/mygui/waitdialog.cpp, compared to
sjek wrote:
in previous fix
Code: Select all
int x = OEngine::Misc::Rng::rollDice(hoursToWait);
if (x > fSleepRandMod * hoursToWait)
mInterruptAt = hoursToWait - int(fSleepRestMod * hoursToWait)
here is the results:
//(x > fSleepRandMod * hoursToWait) //Sjek's formula
hours: 1 Interruptions: 0/100,000
hours: 2 Interruptions: 50,114/100,000
hours: 3 Interruptions: 66,794/100,000
hours: 4 Interruptions: 50,232/100,000
hours: 5 Interruptions: 60,108/100,000
hours: 6 Interruptions: 66,571/100,000
hours: 7 Interruptions: 71,463/100,000
hours: 8 Interruptions: 62,612/100,000
hours: 9 Interruptions: 66,423/100,000
hours: 10 Interruptions: 70,145/100,000
hours: 11 Interruptions: 72,813/100,000
hours: 12 Interruptions: 66,624/100,000
hours: 13 Interruptions: 69,208/100,000
hours: 14 Interruptions: 71,334/100,000
hours: 15 Interruptions: 73,386/100,000
hours: 16 Interruptions: 68,721/100,000
hours: 17 Interruptions: 70,750/100,000
hours: 18 Interruptions: 72,279/100,000
hours: 19 Interruptions: 73,656/100,000
hours: 20 Interruptions: 69,673/100,000
hours: 21 Interruptions: 71,268/100,000
hours: 22 Interruptions: 72,750/100,000
hours: 23 Interruptions: 73,824/100,000
hours: 24 Interruptions: 70,825/100,000
//(x < fSleepRandMod * hoursToWait) //The Current Formula
hours: 1 Interruptions: 100,000/100,000
hours: 2 Interruptions: 49,886/100,000
hours: 3 Interruptions: 33,206/100,000
hours: 4 Interruptions: 24,910/100,000
hours: 5 Interruptions: 39,892/100,000
hours: 6 Interruptions: 33,429/100,000
hours: 7 Interruptions: 28,537/100,000
hours: 8 Interruptions: 25,032/100,000
hours: 9 Interruptions: 33,577/100,000
hours: 10 Interruptions: 29,855/100,000
hours: 11 Interruptions: 27,187/100,000
hours: 12 Interruptions: 24,922/100,000
hours: 13 Interruptions: 30,792/100,000
hours: 14 Interruptions: 28,666/100,000
hours: 15 Interruptions: 26,614/100,000
hours: 16 Interruptions: 24,972/100,000
hours: 17 Interruptions: 29,250/100,000
hours: 18 Interruptions: 27,721/100,000
hours: 19 Interruptions: 26,344/100,000
hours: 20 Interruptions: 25,268/100,000
hours: 21 Interruptions: 28,732/100,000
hours: 22 Interruptions: 27,250/100,000
hours: 23 Interruptions: 26,176/100,000
hours: 24 Interruptions: 25,034/100,000
Code: Select all
#include <iostream>
#include <cstdlib>
#include <ctime>
int main() {
int hours=1;
while (hours < 25){
int counter=0;
int runs=100000;
while ( runs > 0 ){
if( static_cast<int>((std::rand()/(static_cast<double>(RAND_MAX)+1.0)) * (hours)) > 0.25*hours ){
counter++;
}
runs--;
}
std::cout << "hours: " << hours << " Interruptions: " << counter << "/100,000" << std::endl;
hours++;
}
return 0;
}
the only difference being the direction of the inequality (> vs <)