1. ## random number generator

I have an array int arr[10];

I want to fill the array up with random numbers between

int low = 5;
int high = 15;

How would I do this? From what I know, I think I need the <cstdlib> and I need some kind of rand function. But thats all I know. Can anybody help? Thanks in advance!

2. Yes, read this tutorial on using rand. After that, it's pretty easy.

3. It depends on whether you are allowed to have duplicates or not. If you want 5, 6, 7, 8, 9, 10, 11, 12, 13, and 14 in some random order in the array, then you should put them into the array in order using a for loop, then use random_shuffle to shuffle the values in the array. If you just want 10 random numbers from 5 to 15, then use a loop to get 10 random numbers and store them in the array.

To get a single random number from 5 to 15, look in the FAQ for the proper formula to use with rand(). Prelude's tutorial is probably unnecessarily complex for this problem.

4. Originally Posted by Daved
It depends on whether you are allowed to have duplicates or not.
If you force non-repeating numbers, the numbers aren't random because each number relies on the numbers that came before...

5. I read the website given and I still can't figure it out.

6. - Declare the array to be 10 integers.
- Seed rand.
- Call rand 10 times but make sure that the value you want is in the range 5 to 15.
- put what rand returns in the array each time.

7. If you force non-repeating numbers, the numbers aren't random because each number relies on the numbers that came before...
It depends on the definition of randomness and doesnt really matter since the pseudo-random numbers depend on the seed, anyway.

8. >> I read the website given and I still can't figure it out.
Did you read the FAQ on this website? Have you tried coding anything yet? Did you code the declaration of the array? How about the for loop that sets 10 numbers? Have you figured out that you need to call srand() once at the start of the program? Have you figured out the proper way to do that? If you have any of that, show us what you've coded.

The hard part for you will probably be making the result from rand() fit in between 5 and 15, but you should get the other stuff done first and make sure itis working.