# Random number generator

• 03-14-2011
jbone0881
Random number generator
so, for this assignment they introduce the rand() function and also(finally) other libraries to use. anyway, the first program is as follows:

Write a program that will print out 10 random integers between 10 and 25. Prompt the user to enter the seed from which the random sequence will grow.

i used an example out of my text, but naturally it didn't work. i also asked my t.a.'s about it and they didn't know how to do it either. this left me thrilled. anyway, i was wondering what anybody thought of this.

Code:

```#include <stdio.h> #include <stdlib.h> int main() {   int x, i,z;   printf("Enter a number between 10 & 25.\n");   scanf("%d", x);   printf("10 random numbers between values are as follows:\n");   for(i=0; i<10; i++)   {       z=10 + (srand(x) % 25);       printf("%d\n", z);   }     return 0; }```
• 03-14-2011
quzah
You only seed rand once. That is to say, you only call srand once. Then to get a number, you call rand.

Quzah.
• 03-14-2011
jbone0881
cool, i got it. thanks.

Code:

```#include <stdio.h> #include <stdlib.h> int main() {   int seed, i,z;     printf("RAND_MAX = %d\n", RAND_MAX);           printf("Enter seed:");   scanf("%d", &seed);           srand(seed);   printf("10 random number between values are as follows:\n");   for(i=0; i<10; i++)   {       z=10 + (rand() % 16);       printf("%d\n", z);   }     return 0; }```
• 03-14-2011