1. ## random function

How do you make a random function work?

other questions:
where do you type the variable that you assign the rndm number to?
where do you type the highest number the rndm thing will go to?
umm........
jus plain how do you do it?

2. Code:
`int x = rand () % 10;   // max is 9`
any ?uestions?

3. how do you make a maximum of....well......10?

4. change the '10' to '11'...

5. ## To DoubleAnti

> doubleanti
> title: grand wierdo

I believe it's spelled weirdo

6. Random numbers have been covered a lot in the past couple of weeks. Read some more threads. LOOK UP.Between the buttons marked faq (probably some sort of self-destruct as no-one seems to see this) and home is another that says search on it. Do you think thats there just to look pretty like the faq button?? dont u guys do any research of your own.

7. heh... it's all part of the wierdosity man... all part of it...

8. Simple bluehead...go to my message board I'll tell you how the modulus operator works with rand()

9. ## To...

To put it simple. Ok, you want a random number. Go like this:

Example: x=rand() % 10;

That means anywhere from 0 to 10, INCLUDING 10. If you want to set another boundry, go like this:

Example: x=5 + rand() % 10;

That means anywhere from 5 to 10, inclusive. Meaning 5 and 10 are included. Think of it like this 5>=rand()>=10. Those are greater-than-or-equal-to signs.

If you want it to generate random numbers in a different pattern each time, you must enter this before you do the rand() thing:

srand(time (NULL) );

That will make it a different pattern of random numbers according to the time clock. Or if you wanted you could go like this:

unsigned random;
cout<<"Enter number: ";
cin>>random;
srand(random);
x=5 + rand() % 10;

Ok that will change the patter according to what the user enters. Make sure if you do it the time clock way, include "time.h". And for srand(); you need "windows.h". Well, that just about covers it.

10. Example: x=rand() % 10;

That means anywhere from 0 to 10, INCLUDING 10.
Wrong. a % b never equals b:
Code:
```#include <cstdio>

int main()
{
for(int i = 0; i < 20; i++)
printf("%2d % 10 = %d\n", i, i % 10);

return 0;
}```

11. ## Yikes, lots of errors

Example: x=rand() % 10;
That means anywhere from 0 to 10, INCLUDING 10.

Nope! It is from 0 to 9 (including 9). See this link for an earlier discussion on this:

If you want to set another boundry, go like this:
Example: x=5 + rand() % 10;

That means anywhere from 5 to 10, inclusive. Meaning 5 and 10 are included.

Wrong again. That means anywhere from 5 to 14 (including 14).

Think of it like this 5>=rand()>=10. Those are greater-than-or-equal-to signs.

I want to see that number, which is greater than 10 but smaller than 5...

And for srand(); you need "windows.h".

Umm, srand() is in stdlib.h. Well, it IS possible that windows.h includes stdlib.h also...

Well, if you're still (confused) over this. Make a program that generates some random numbrs and see where the boundries are.