Last active
August 29, 2015 14:02
-
-
Save ForTheYin/c8ad95a6851602a6c6fe to your computer and use it in GitHub Desktop.
Memory Random (mem_random)
This file contains hidden or 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
#include <stdio.h> | |
#include <stdlib.h> | |
// returns a random number | |
int mem_random(int seed){ | |
int* seed_ptr = (int*) malloc(sizeof(int)); | |
*seed_ptr = seed; | |
// shift the pointer by some amount, should point to something random | |
void* random_ptr = ((char*)seed_ptr) + 1; | |
int output = *((int*) random_ptr); | |
// don't forget memory leak! | |
free(seed_ptr); | |
return output; | |
} | |
int main(void) | |
{ | |
printf("output: %d\n", mem_random(18)); | |
printf("output: %d\n", mem_random(623)); | |
printf("output: %d\n", mem_random(1234)); | |
printf("output: %d\n", mem_random(1345)); | |
printf("output: %d\n", mem_random(4000)); | |
printf("output: %d\n", mem_random(4567)); | |
printf("output: %d\n", mem_random(1231234)); | |
printf("output: %d\n", mem_random(132344125)); | |
printf("output: %d\n", mem_random(914685690)); | |
printf("output: %d\n", mem_random(1898756907)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The horror...