Thread: rand() question

  1. #1
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369

    rand() question

    If I did

    Code:
    cout << rand()%4;
    would 0 be a possible outcome? 4?
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Possible outcomes are 0, 1, 2, 3. Four is not possible.

    mod % returns the reminder. Therefore, 8 % 4 has a zero remainder. While the remainder of 7 % 4 is 3 and 9 % 4 is 1. Four can never be a reminder.

Popular pages Recent additions subscribe to a feed