using random()

Posted By: felixfx

using random() - 11/13/19 02:11

hi, I'm testing the random number generator and I cannot seem to get random(1); to have an output other than zero.

I may be utilizing it incorrectly. The zorro.chm file saids

random(var max): var // suppose to return a number between 0 and max

my code looks like this:

function run()
{

int number = random(1);

if (number == 0) printf("\nZero");
if (number == 1) printf("\nOne");

}

Any ideas? Thanks!
Posted By: felixfx

Re: using random() - 11/13/19 03:24

also, i noticed that the argument to the random() function is supposed to be a var and returns a var, but if i use

var number = random(1); it returns no output, which i also find odd.
Posted By: felixfx

Re: using random() - 11/13/19 04:17

wow, i feel pretty dumb. the max argument means up to but not including. which means random(2) outputs 0 and 1.

Problem Solved
© 2024 lite-C Forums