Lottery.m

#1

I know that this is a nitpick, but shouldn’t

``````firstnumber = ((int)random() % 100) +1;
secondnumber = ((int)random() % 100) +1;``````

be coded as

``````firstnumber = ((int)random() % 100) +1;
do {
secondnumber = ((int)random() % 100) +1;
} while (secondnumber == firstnumber)``````

in order to prevent the (admittedly unlikely) outcome of randomly choosing the same number twice?

#2

That looks like a fine improvement to me. Admittedly lotteries are not our forte.

#3

Nice
This is not meant as criticism nor should it be taken too seriously:

actually, the use of a loop is not the best of ideas. Potentially, you can run into an endless loop - yes, not very likely, but the universe at times take strange twists and turns. Also, you might have to do this a million times over, potentially losing a lot of time (at least half a mili-second )

A ‘better’ implementation would be (in pseudo code):

``````firstNumber = random number between 1 and 100
rangeForSecondNumber = random number between 0 and 1 // 0 being lower range, 1 being upper range
if( rangeForSecondNumber == 0  && firstNumber > 1) {
secondNumber = random number between 1 and (firstNumber - 1)
}
else {
secondNumber = random number between (firstNumber + 1) and 100
}``````

Nitpicking can be fun