Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Testing: http://pastebin.com/9D3G0w8R
- Where it says "// get_random_number implementation", the implementation is obtained via the above URL
- */
- // Test 1 -- does it have collisions?
- // C
- #include <stdio.h>
- // get_random_number implementation
- int
- main()
- {
- for(int i = 0; i < 65536; i++)
- printf("%i\n", get_random_number(i));
- }
- /*
- Bash
- gcc test.c && ./a.out | vim -
- Vim
- :%!sort -u
- :file
- :q!
- Output
- (initial)
- 44253
- 22970
- ...
- 21283
- 0
- (:%!sort -u)
- 0
- 1
- 10
- 100
- ...
- 9998
- 9999
- (:file)
- "[No Name]" [Modified] 65536 lines --100%--
- */
- // Test 2 -- does it get stuck?
- // C
- #include <stdio.h>
- #include <time.h>
- // get_random_number implementation
- int
- main()
- {
- int i = 0;
- int seed = time(0) & 0xFF;
- while(seed = get_random_number(seed)) // Terminates when seed = 0
- printf("Generation #%i: %i\n", i++, seed);
- }
- /*
- Bash
- gcc test.c && ./a.out
- Output
- (1)
- Generation #0: 16088
- Generation #1: 3413
- Generation #2: 19262
- ...
- Generation #36118: 29834
- Generation #36119: 65535
- (loop terminates)
- (2)
- gcc test.c && ./a.out
- Generation #0: 32958
- Generation #1: 30947
- Generation #2: 36052
- ...
- Generation #33428: 29834
- Generation #33429: 65535
- (loop terminates)
- (3)
- gcc test.c && ./a.out
- Generation #0: 24657
- Generation #1: 16074
- Generation #2: 39231
- ...
- Generation #9793: 29834
- Generation #9794: 65535
- (loop terminates)
- */
- // Test 3 -- can it access all values?
- // C
- #include <stdio.h>
- #include <time.h>
- // get_random_number implementation
- int
- main()
- {
- int orig = time(0) & 0xFF;
- int seed = get_random_number(orig);
- for(int i = 0; seed != orig; i++, seed = get_random_number(seed)) // Terminates When seed wraps around to original value
- printf("Generation #%i: %i\n", i, seed);
- }
- /*
- Bash
- gcc test.c && ./a.out
- Output
- (1)
- Generation #0: 63458
- Generation #1: 33527
- Generation #2: 45080
- ...
- Generation #65533: 45579
- Generation #65534: 50268
- (loop terminates)
- (all other tests end at the same number of generation. It's 65534 because after 50268 is another value that isn't displayed, and after that value is the value before generation #0, also not displayed. 65536 - 2 = 65534)
- */
Add Comment
Please, Sign In to add comment