Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 2
    openssl is way overkill for this. Commented Mar 3, 2014 at 0:15
  • 2
    @TimWolla: I'm not sure what you mean by "overkill", but note: 1) There is nothing in the question that indicates the purpose or how "random" the number is to be, and 2) In my tests, the answer I proposed runs considerably faster than the accepted answer. 3) Instead of creating two functions as with the accepted answer, my answer is a single line of code. Commented Mar 3, 2014 at 2:37
  • <?php foreach(range(0,100) as $n){echo("<div style='background-color:#".(bin2hex(openssl_random_pseudo_bytes(3))).";padding:1em;'></div>");}?> shows that this gives the most colourful and random results. Try it with phpfiddle.org! Commented Oct 31, 2017 at 15:19