1
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;

int main(){
    system("cls");
    cout<<randomize();
    cout<<random();
    return 0;
}

It is giving an error: identifier "random() is undefined","randomize() is undefined".
I have just installed VS code and mingw and have set the path of mingw also i have installed the extensions C/C++ by Microsoft and Code runner in VS code.

Jaatz14
  • 11
  • 6
  • 3
    Where did you get those function names from? Standard C++ doesn't have such functions. [`random()`](https://linux.die.net/man/3/random) seems to be a POSIX function (i.e. it'd work if you were on Linux, not sure if there's a way to get it work on MinGW), and I can't find any information on `randomize()`. – HolyBlackCat Oct 11 '20 at 10:35
  • 1
    That you're not using [``](https://en.cppreference.com/w/cpp/numeric/random) and all its glory in a modern C++ program is itself a proper question to consider. Just saying. – WhozCraig Oct 11 '20 at 10:36
  • @HolyBlackCat this code is working in turbo c++ ;( – Jaatz14 Oct 11 '20 at 12:24
  • @RishabhSingh I can believe in those two functions working in Turbo C++, but the whole code couldn't have worked, because Turbo C++ doesn't have namespaces. Turbo C++ is an ancient compiler from the previous millenium. It predates the earliest C++ standard, so it's noticeably different compared to modern compilers, which all try to adhere to the same standard. – HolyBlackCat Oct 11 '20 at 14:59
  • @HolyBlackCat Yup you are right, thanx though. – Jaatz14 Oct 11 '20 at 17:14

1 Answers1

1

You are probably looking for:

  • std::srand() to set the seed (randomize)- but you'll have to provide an argument to make it more random
  • std::rand() to get a random number (random)

But if you want to do more elaborate work with random numbers in C++, it'll be worth to have a look at the real C++ <random> library and at this SO question

Christophe
  • 68,716
  • 7
  • 72
  • 138