-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Negative random value where positive value is required
The function MythRandom(), introduced in commit 31a811e, does create a 32-bit random value which is returned in an uint32_t. This new function does replace the Linux system call random() which returns an int. Note that int value returned by random() is always positive. In places where an int is required the output of MythRandom() is cast to an int. This value can however be negative and will be approximately 50% of the times it is called. This is now fixed in the places where it had not been fixed alreay.
- Loading branch information
Showing
4 changed files
with
4 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181a1b8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it make sense to also limit MythRandom to the range from 0 to 2^31 - 1. That would match the behavior of the random() system call it replaced, and should prevent any similar problems in the future.
181a1b8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would possibly break the code in other places where MythRandom is now used. I did check all usage of MythRandom and I think everything is OK now.