I learn C++ in school and there we use Turbo C++. However at home I use either Dev C++ or terminal in Ubuntu to compile programs.
The functions randomize()
and random()
are used regularly and we include stdlib.h
to call them. But in Dev and terminal i get an error saying that the function does not exist.
What could be the reason for this and what can I use as a substitute?

- 351
- 2
- 3
- 9
-
5Aren't both of these prehistoric? – CodesInChaos Apr 20 '15 at 13:04
-
1Why don't you use `rand()`? – Manwal Apr 20 '15 at 13:06
-
2I'm not surprised your compiler doesn't support functions from a non standard 25 year old compiler. – NathanOliver Apr 20 '15 at 13:07
-
I learned C with Turbo C. The function you should use is rand() or if your compiler supports it (which I think it should, not Turbo C) std::rand (defined in cstdlib). – Robinson Apr 20 '15 at 13:09
-
Similar question: [What difference between `rand()` and `random()` functions?](http://stackoverflow.com/questions/18726102/what-difference-between-rand-and-random-functions) – CodesInChaos Apr 20 '15 at 13:14
-
1You should be aware that Turbo C++ understands an ancient dialect of C++. If you are learning C++ to be competitive in today's job market, you should clearly understand the limitations of Turbo C++. – n. m. could be an AI Apr 20 '15 at 13:48
2 Answers
These are not standard C or C++ functions. In standard C and C++ there are srand
and rand
which are part of the <stdlib.h>
header.
These functions are probably part of Turbo C++ to improve compatibility with Turbo Pascal, where randomize
and random
are the default random number generator.
Unfortunately the quality of this generator sucks very very much. Modern C++ has better alternatives, but since both Turbo C++ and Dev++ are pretty old, you won't be able to use them.

- 106,488
- 23
- 218
- 262
-
Dev-C++ has many distributions, some old, some new. But either way, its oldness is not entirely relevant, since the compiler and libraries it uses are configurable. So you can set it to use a C++11 implementation, and some distributions come with that packaged in. – Benjamin Lindley Apr 20 '15 at 13:25
The function which you are talking about has been replaced from standards, some compiler however still continue to support them, but you wont find these function in gcc compier (in your case ubuntu terminal) now in standard there are two function in library <cstdlib> (stdlib.h)
rand
and srand
. You should use them to achieve your purpose. for your reference http://www.cplusplus.com/reference/cstdlib/

- 1,874
- 1
- 20
- 32