errori n code blocks random was not declared in this scope

sachin vishnoi

Estimable
Sep 7, 2014
1
0
4,510
0
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
 
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
R Apps General Discussion 11
C Apps General Discussion 2
C Apps General Discussion 3
henrytcasey Apps General Discussion 1
S Apps General Discussion 3
J Apps General Discussion 1
C Apps General Discussion 1
Mighty Apps General Discussion 9
A Apps General Discussion 8
A Apps General Discussion 1
J Apps General Discussion 1
O Apps General Discussion 1
G Apps General Discussion 0
R Apps General Discussion 4
kol12 Apps General Discussion 7
J Apps General Discussion 6
Durwesh Naeem Apps General Discussion 2
P Apps General Discussion 2
R Apps General Discussion 1
g-unit1111 Apps General Discussion 7

ASK THE COMMUNITY