random() - can't use in C::B

I'm unable to use the function random(num); in Code::Blocks.
it shows the error :
error: 'random' was not declared in this scope
while the same code works fine in Borland's Turbo C++.

please tell, how do I rectify this?
You probably want rand() or something from the <random> header.

http://www.cplusplus.com/reference/cstdlib/rand/
http://www.cplusplus.com/reference/random/
Last edited on
random() is indeed implemented on Borland's Turbo C++, but it uses rand() behind the scenes anyway.
http://ltcpp.blogspot.ro/2012/09/c-functions-to-generate-random-numbers.html
The moral of the story is don't use Turbo C++.
@iHutch105
The moral of the story is don't use Turbo C++.

true.

@modoran
that article is copied from the book COMPUTER SCIENCE with C++ Class XI
by Sumita Arora , and that book completely emphasize on Turbo C++.
I don't know from what book is copied and I don't care.

I usually don't use srand() and rand() on my programs, for windows I use something like this, much better than rand:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <Windows.h>
#include <wincrypt.h>
#include <stdio.h>

int main() {
  HCRYPTPROV prov;
  if (CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, 0)) {
    long int li = 0;
    if (CryptGenRandom(prov, sizeof(li), (BYTE *)&li))
      printf("Random number: %ld\n", li);
    CryptReleaseContext(prov, 0);
  }
  return 0;
}


For Linux and Mac OS just read from /dev/urandom as you do with any regular file.
for this i have to study the
<wincrypt.h>
library first and it is larger in length as compared to srand() and rand().
maybe somewhere it may could be better, but i don't have any idea about it.
Last edited on
Topic archived. No new replies allowed.