vendredi 21 septembre 2018

Why I got pattern with rand()?

I tried to create a bmp file, like this:

 uint8_t raw_r[pixel_width][pixel_height];
 uint8_t raw_g[pixel_width][pixel_height];
 uint8_t raw_b[pixel_width][pixel_height];
 uint8_t blue(uint32_t x, uint32_t y)
 {
     return (rand()%2)? (x+y)%rand() : ((x*y%1024)%rand())%2 ? (x-y)%rand() : rand();
 }
 uint8_t green(uint32_t x, uint32_t y)
 {
     return (rand()%2)? (x-y)%rand() : ((x*y%1024)%rand())%2 ? (x+y)%rand() : rand();
 }
 uint8_t red(uint32_t x, uint32_t y)
 {
     return (rand()%2)? (y-x)%rand() : ((x*y%1024)%rand())%2 ? (x+y)%rand() : rand();
 }

 for (y=0; y<pixel_height; ++y)
 {
     for (x=0; x<pixel_width; ++x)
     {
         raw_b[x][y]=blue(x, y);
         raw_g[x][y]=green(x, y);
         raw_r[x][y]=red(x, y);
     }
 }

I excepted to get something random. However, the output is interesting:

enter image description here

Do you know the reason why?




Aucun commentaire:

Enregistrer un commentaire