Created
May 4, 2015 22:13
-
-
Save samhocevar/781ed03690972c56de3f to your computer and use it in GitHub Desktop.
Using a PRNG to hash integers
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> | |
int const WIDTH = 512; | |
int const HEIGHT = 512; | |
int main(int argc, char *argv[]) | |
{ | |
/* Pass the seed as the first argument */ | |
int seed = argc > 1 ? atoi(argv[1]) : 0; | |
int x, y, tmp; | |
printf("P2\n"); | |
printf("# Test image\n"); | |
printf("%d %d\n", WIDTH, HEIGHT); | |
printf("255\n"); | |
for (y = 0; y < HEIGHT; ++y) | |
{ | |
for (x = 0; x < WIDTH; ++x) | |
{ | |
srand(seed); tmp = rand(); | |
srand(tmp + x); tmp = rand(); | |
srand(tmp + y); tmp = rand(); | |
printf("%d ", (int)(tmp * 255.f / RAND_MAX)); | |
} | |
printf("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment