# Thread: passing random values into array

1. ## passing random values into array

So here is my issue,

the range is 1 to 49, inclusive in an array.
You must input how many integers you wish to show on the output. (lets say 12 is your input).

The expected random output should be for example
------------------------
1
3
47
3
1
3
47
44
26
47
49
26

1 appears 2 times
2 appears 0 times
3 appears 3 times
.....
26 appears 2 times
....
44 appears 1 times
...
47 appears 3 times
48 appears 0 times
49 appears 1 times
----------------------------------
For a total of 12 times

Here is what i have so far.
Code:
```#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int random[49];
int value;
int i;
int numtogen2;

printf("Enter the number of random integers to generate.\n");
scanf("%d",& numtogen2);

for(i=0;i<numtogen2;i++)
{
value=(rand()%49)+1;
printf("%d\n",value);

printf("%d is shown %d times\n", value, random);

}

}```
My main issue is passing the output values into the array, I know im missing some code, just wondering what that would be or how it would look like.

2. To get or set a number from an array you generally use brackets:
Code:
```int random[49];
//set some values
random[0] = 5;
random[1] = 0;
random[1] += 1;

//print them
printf("random[0]=%d\n random[1]=%d\n", random[0], random[1]);```
This should get you in the right direction.

3. I believe there's a FAQ on generating random numbers.

Quzah.

4. You need to seed the random number generator. Most common way to do this is to #include <time.h> and call

srand(time(NULL));

5. Code:
`scanf("%d",& numtogen2);`
No space after the '&'.

6. Originally Posted by nonoob
Code:
`scanf("%d",& numtogen2);`
No space after the '&'.
Whitespace doesn't matter there.

Quzah.

7. Thanks, quzah. I stand corrected. I expected hideous compiler blow-ups which the OP would have noticed sooner or later since "boolean and" is missing a left argument.

8. Whitespace in most cases doesn't matter. Also, that & there isn't the "boolean and" in this case, it's the "address of" operator. Used to get the address of a variable (for functions expecting pointers as arguments and the like).
Code:
```int x, *p;

x = 5;
p = &x; /* assign the address of x to the pointer p */```

Quzah.

9. Also, that & there isn't the "boolean and" in this case, it's the "address of" operator.
I think the point was that he thought the compiler would recognize & as the boolean and instead of address of since there was a space and boolean and is usually written with the space there, as opposed to address of which is usually written without a space between the variable and operator. Of course since whitespace doesn't matter at all in C this is not the case.

Actually I wonder if it is even possible to get a
"boolean and" is missing a left argument.
error. As far as I know the compiler would assume it's address of if that ever happened.