Sunday, July 13, 2014

Tip for never duplicating random values

Hi all, here's a programming tip for when you want to make some random values but never want the random values to repeat themselves.

Say that you want two random values, but you want to make sure that they are different. Well in php, you can do that with a simple while loop. Check out the code below:

$firstNumber = rand(0,10);
$secondNumber = $firstNumber;
while($secondNumber == $firstNumber) {
     $secondNumber = rand(0,10);

With this code, the variable secondNumber is set to equal firstNumber, and a new random value will be generated for secondNumber until it is not the same as firstNumber. This can be useful if you want to make sure that all information you display is unique!

In other news, an update for Lamb in a Pram will be coming soon. This will include 8 new items, the ability to change pram color, and a few bug fixes.

Also, a limited lite version of Lamb in a Pram will be coming out for free!


James Grams

No comments: