Skip to content

Instantly share code, notes, and snippets.

@ForTheYin
Last active August 29, 2015 14:02
Show Gist options
  • Save ForTheYin/c8ad95a6851602a6c6fe to your computer and use it in GitHub Desktop.
Save ForTheYin/c8ad95a6851602a6c6fe to your computer and use it in GitHub Desktop.
Memory Random (mem_random)
#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));
}
@TheBuzzSaw
Copy link

The horror...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment