Requirement
Sorry it sounds like an homework assignment but I need this feature for a dll I'm implementing in our project.
- I have an array of strings.
- Each string is of length 16 of random chars [0-9a-z]
- I want to map each string to a random number in range [0,100]
- String 'X' will always be mapped to number 'Y'
Attempt
for (string strLine; std::getline(filein, strLine);)
{
int iSum = 0;
for (const auto& c : strLine)
iSum += static_cast<int>(c);
int iRand = iSum % 101;
using namespace std;;
fileout << strLine << "\t" << iSum << "\t" << iRand << endl;
}
Problem
I run this on a 1000 random strings. The results are not uniform. For example, I see 23 times the random number 65 while I only see 1 time the random number 83.
This is not a surprise since my mapping function is embarrassing.
I tried looking at Pseudo-random number generation and kinda got lost.
Aucun commentaire:
Enregistrer un commentaire