Random numbers in Bloodshed dev. RRS feed

  • Question

  • Random numbers in Bloodshed dev.

    Hi! I am currently learning C, and I need help with generating random numbers.

    I use the Bloodshed compiler, and I do the normal thing for generating a number from 1 to, say, 5.
    int num;

    num = rand();

    num = (((float)num/RAND_MAX)+ 1) + 4; //make a number from 1-5 instead
    printf("%i\n", num); // of 1 - RAND_MAX

    It kinda works, but the 'random' number seems to increase along with the time every time I run it.

    Is there a way to fix this, or is there something wrong with the code?
    Wednesday, November 14, 2007 10:43 AM