Sign in with
Sign up | Sign in
Your question

errori n code blocks random was not declared in this scope

Tags:
  • Programming
  • Apps
Last response: in Apps General Discussion
Share
September 7, 2014 9:21:51 AM

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

More about : errori code blocks random declared scope

a b L Programming
September 7, 2014 7:07:21 PM

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,

  1. int my_random_value = 0;
  2. int my_max_value = 500;
  3. 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

  1. my_random_value = (rand() % my_max_value) + 1
m
0
l
September 7, 2014 9:30:57 PM

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
  1. #include <stdlib.h>

appears in the first couple of your source file.
Help on rand and random can be obtained on the command line
  1. man 3 rand
  2. man 3 random
m
0
l
!