Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to use the "rand" instruction

+4 votes
asked Jan 26, 2023 by Manuel Sevilla (160 points)

1 Answer

0 votes
answered Jan 27, 2023 by Peter Minarik (86,040 points)
edited Jan 27, 2023 by Peter Minarik

Which language? For C, see this manual for details and examples.

A quick example:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main ()
{
    srand(time(NULL)); // Initialzie the random number generator with a random seed.
    int randomNumber = rand() % 100 + 1; // Generate a random number berween 100 (0..99 + 1)
    printf("The random number is: %d\n", randomNumber);
    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...