answersLogoWhite

0

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

int GetRand( int min, int max)

{

// Swap min and max if wrong way around.

if(max<min)min^=max^=min^=max;

return(rand()%(max-min+1)+min);

}

int main()

{

// Seed the random number generator with current time to ensure

// random numbers are different on each run.

// Note: use srand(1) to generate the same sequence on every run.

srand((unsigned)time(NULL));

printf("Number from 0 to 10 : %d\n", GetRand(0,10));

printf("Number from 1 to 100: %d\n", GetRand(1,100));

return(0);

}

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

How do you make cmd generate a random number between two variables that can be changed at anytime?

In DOS, the following line will generate a random number between 1 and 100. To get 0-100, remove the plus one at the end. set /a num=%random% %%100 +1


How are cell phone numbers assigned?

When telephone numbers were invented, they were short - as few as two or three digits - and were used by people to call a few neighbors. As phone systems have grown and interconnected to encompass the world, telephone numbers have grown longer and more complex, and in addition to telephones they now designate many other devices, such as computers and fax machines.


Why do you use pseudorandom numbers in simulation?

Generation of random numbers is not a simple process. In order for a number to be truly random it must be uniformly distributed (each random number in the interval of random numbers has equal chance of being selected), efficiently generated (the random numbers hsould not degenerate into constant values or recycle too frequently) and absent of patterns. Computers can generate random numbers using a mathematical process that artificially creates psuedorandom numbers more efficiently than true random numbers can be generated in a process akin to spinning the roulette wheel.


What is the process for generating a random decimal number in Python using the random module?

To generate a random decimal number in Python using the random module, you can use the random.uniform() function. This function takes two arguments, which are the lower and upper bounds of the range from which the random decimal number will be generated. For example, to generate a random decimal number between 0 and 1, you can use random.uniform(0, 1).


What are two prime numbers that would generate 400?

There are no two prime numbers that would generate 400. The prime factorization of 400 is 2^4 * 5^2, which means it can be expressed as the product of two powers of primes, but not as the product of two distinct prime numbers.


What is the probability of getting two prime numbers 1-10?

The probability of getting two prime numbers when two numbers are selected at random and without replacement, from 1 to 10 is 2/15.


What is plus times plus?

The product of two positive numbers is positive.


Write a java application that generates two random numbers using built in method math random ranging 5 to 8 the program should use another built in method to calculate the power of xy the x value is t?

write a java application that generate custemer account balance in a banking system?


What numbers is it that twelve plus what equals two?

(-10)


Is 27 6 a sum?

No, it is not. Those are just a random group of numbers. A sum is an amount resulting from the adding of at least two numbers.


Does a plus b equals b plus a for any two whole numbers?

Yes.


What is 1.2 plus 1.2 plus 1.2 plus 1.2 plus 1.2 plus 1.2 plus 1.2 plus 1.2 plus 1.2 plus 1.2?

The answer is 12. Simply add the numbers together like you would for two plus two. To check your work, a calculator is the best option.The answer is 12. Simply add the numbers together like you would for two plus two. To check your work, a calculator is the best option.