Rename xorshift_basic to xorshift_256
This commit is contained in:
		
							
								
								
									
										33
									
								
								xorshift.c
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								xorshift.c
									
									
									
									
									
								
							| @@ -9,9 +9,10 @@ typedef struct { | |||||||
|   u64 y; |   u64 y; | ||||||
|   u64 z; |   u64 z; | ||||||
|   u64 w; |   u64 w; | ||||||
| } XORShiftBasic; | } XORShift256; | ||||||
|  |  | ||||||
| u64 xor_shift_basic_generate(XORShiftBasic *state); | void test_xorshift_256(Pixel *data, u64 w, u64 h); | ||||||
|  | u64 xorshift_256_generate(XORShift256 *state); | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) { | int main(int argc, char *argv[]) { | ||||||
|   struct timespec ts = {0}; |   struct timespec ts = {0}; | ||||||
| @@ -19,23 +20,31 @@ int main(int argc, char *argv[]) { | |||||||
|  |  | ||||||
|   srand48(ts.tv_nsec); |   srand48(ts.tv_nsec); | ||||||
|  |  | ||||||
|   XORShiftBasic state = { |   u64 w = 1024; | ||||||
|  |   u64 h = 1024; | ||||||
|  |   u64 length = w * h; | ||||||
|  |   Pixel data[length]; | ||||||
|  |  | ||||||
|  | 	test_xorshift_256(data, w, h); | ||||||
|  |  | ||||||
|  |   write_p6_ppm("./outputs/xorshift_256.ppm", w, h, data); | ||||||
|  |  | ||||||
|  |   return EXIT_SUCCESS; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void test_xorshift_256(Pixel *data, u64 w, u64 h) { | ||||||
|  |   XORShift256 state = { | ||||||
|       .x = lrand48(), |       .x = lrand48(), | ||||||
|       .y = lrand48(), |       .y = lrand48(), | ||||||
|       .z = lrand48(), |       .z = lrand48(), | ||||||
|       .w = lrand48(), |       .w = lrand48(), | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   u64 w = 1024; |  | ||||||
|   u64 h = 1024; |  | ||||||
|   u64 length = w * h; |  | ||||||
|  |  | ||||||
|   Pixel data[length]; |  | ||||||
|   for (u64 y = 0; y < h; ++y) { |   for (u64 y = 0; y < h; ++y) { | ||||||
|     for (u64 x = 0; x < w; ++x) { |     for (u64 x = 0; x < w; ++x) { | ||||||
|       u64 i = y * w + x; |       u64 i = y * w + x; | ||||||
|  |  | ||||||
|       u8 pixel = xor_shift_basic_generate(&state) % UINT8_MAX; |       u8 pixel = xorshift_256_generate(&state) % UINT8_MAX; | ||||||
|       data[i] = (Pixel){ |       data[i] = (Pixel){ | ||||||
|           .r = pixel, |           .r = pixel, | ||||||
|           .g = pixel, |           .g = pixel, | ||||||
| @@ -43,13 +52,9 @@ int main(int argc, char *argv[]) { | |||||||
|       }; |       }; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   write_p6_ppm("./outputs/xorshift.ppm", w, h, data); |  | ||||||
|  |  | ||||||
|   return EXIT_SUCCESS; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| u64 xor_shift_basic_generate(XORShiftBasic *state) { | u64 xorshift_256_generate(XORShift256 *state) { | ||||||
|   u64 t = state->x ^ (state->x << 11); |   u64 t = state->x ^ (state->x << 11); | ||||||
|  |  | ||||||
|   state->x = state->y; |   state->x = state->y; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user