Created
September 24, 2011 15:11
-
-
Save mharsch/1239436 to your computer and use it in GitHub Desktop.
randomly access memory within an allocated range
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
Random integer in range algorithm: | |
given that rand() produces a random number between 0 and RAND_MAX (defined in stdlib.h) | |
and we want a random integer (rand_index) between 0 and page_range where page_range = malloc_size / page_size | |
page_range = malloc_size / page_size; | |
if ( RAND_MAX > page_range ) { | |
rand_index = ( rand() % page_range ) * page_size; | |
} else { | |
rand_index = ( rand() * ( page_range / RAND_MAX ) ) * page_size; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment