You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a lot of places, the project uses the C rand() function, even though the project itself is C++11, which has the "new" and fancy <random> header.
C++11 and up projects should always use <random> and one of its PRNGs instead of the severely limited C random functions, whose actual randomness is really platform-dependent and will work differently across libc implementations. Also using modulo to calculate a distribution skews the results. See this talk from STL, in which he describes why rand() is bad. (And also how to use the C++11 <random> header.)
I suggest a small random wrapper function be made that takes a min and max and generates a random number within those. Something like this:
In a lot of places, the project uses the C rand() function, even though the project itself is C++11, which has the "new" and fancy
<random>
header.C++11 and up projects should always use
<random>
and one of its PRNGs instead of the severely limited C random functions, whose actual randomness is really platform-dependent and will work differently across libc implementations. Also using modulo to calculate a distribution skews the results. See this talk from STL, in which he describes why rand() is bad. (And also how to use the C++11<random>
header.)I suggest a small random wrapper function be made that takes a min and max and generates a random number within those. Something like this:
And then use this function in all places where randomness is needed.
The text was updated successfully, but these errors were encountered: