# errori n code blocks random was not declared in this scope

#### sachin vishnoi

##### Estimable
when i write this statement in code blocks
randomize();
and
r1=random(991)+10;
the error is coming random not declared in the scope
and
randomize not declared in the scope

#### Pinhedd

##### Distinguished
Moderator
the function that you are looking for is rand() not random().

rand() will return a random integral number between 0 and RAND_MAX

If you wish to generate a random number less than RAND_MAX, take the modulus of the returned value and your own max value.

For example,

C++:
``````int my_random_value = 0;
int my_max_value = 500;
my_random_value = rand() % my_max_value``````
will generate a random number between 0 and 499. If you wish to normalize this to the range 1 to 500, simply add 1

C++:
``my_random_value = (rand() % my_max_value) + 1``

#### Pinhedd

##### Distinguished
Moderator
the function that you are looking for is rand() not random().

rand() will return a random integral number between 0 and RAND_MAX

If you wish to generate a random number less than RAND_MAX, take the modulus of the returned value and your own max value.

For example,

C++:
``````int my_random_value = 0;
int my_max_value = 500;
my_random_value = rand() % my_max_value``````
will generate a random number between 0 and 499. If you wish to normalize this to the range 1 to 500, simply add 1

C++:
``my_random_value = (rand() % my_max_value) + 1``

#### Alabalcho

##### Judicious
CodeBlocks can be used for variery of programming languages. Assuming that you're using it for C/CPP, you might also want to make sure
Code:
``#include <stdlib.h>``
appears in the first couple of your source file.
Help on rand and random can be obtained on the command line
Code:
``````man 3 rand
man 3 random``````

Thread starter Similar threads Forum Replies Date
Apps General Discussion 11
Apps General Discussion 2
Apps General Discussion 3
Apps General Discussion 1
Apps General Discussion 3
Apps General Discussion 1
Apps General Discussion 1
Apps General Discussion 9
Apps General Discussion 8
Apps General Discussion 1
Apps General Discussion 1
Apps General Discussion 1
G Apps General Discussion 0
Apps General Discussion 4
Apps General Discussion 7
Apps General Discussion 6
Apps General Discussion 2
Apps General Discussion 2
Apps General Discussion 1
Apps General Discussion 7