P
P
polyvoidex2018-04-16 00:30:20
PHP
polyvoidex, 2018-04-16 00:30:20

How to remove artifacts in the random number generator (rand function)?

I am creating a 512x high resolution texture pack for Minecraft. Images must consist of randomly placed pixels of two colors. To do this, I use a browser in which I create an image from one-pixel divs grouped via float:left.

<?php

echo '<style>
#q{background:#FFF}
#w{background:#000}
#q,#w{float:left;width:1px;height:1px}
</style>';

echo '<div style="width:128px;height:128px">';

for($i=0;$i<(128*128);$i++){
  if(0==rand(0,1)){
    echo '<div id="q"></div>';
  }else{
    echo '<div id="w"></div>';
  }
}

echo '</div>';

?>

At the output, I want to get a sand pattern, but sequences of stripes of identical dots appear:
5ad3c1e150123550491283.gif5ad3c1e9401e6641302537.gif5ad3c1f255e05772858444.gif
What is happening?
  • Is my browser (Opera 52 64-bit) not rendering markup correctly?
  • Under some conditions, does the rand function (PHP 5.2.9) deviate the possible generation of a number in one direction or the other?
  • Is my hardware (AMD FX-4300) not working properly?
  • Everything is correct. This is how it should be with random generation.

Mathematicians, enlighten!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twobomb, 2018-04-16
@polyvoidex

https://jsfiddle.net/wx10sh6x/4/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question