xStimpert
xStimpert

Reputation: 13

SRAND() is not working in codeblocks?

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


int main ()
{
    srand(5);

    int r = rand() % 100

    cout << r << endl;
}

codeblocks throwing this error back saying i didn't declare srand or rand when i need them to just generate random numbers? I know it returns the same nmber everytime as i am learning cpp rn.

Upvotes: 0

Views: 3252

Answers (2)

Viswa
Viswa

Reputation: 326

"SRAND", which stands for "Seed Rand", is used to obtain seemingly random numbers in the true sense.

    #include<iostream>
    #include<cstdlib>
    #include<cstdio>
    #include<ctime>

using namespace std;
int main()
{
cout<<"The Random Number is "<<endl;
srand(time(0));
cout<<(rand())<<endl;
return 0;
}

This can be used to generate OTP's, and other applications in gaming, cryptography, and statistics.

Upvotes: 0

Edd
Edd

Reputation: 1370

Put this at the top

#include <cstdlib>

Upvotes: 1

Related Questions