#i need a random number between 1 to 100 for a number game im making

60 messages · Page 1 of 1 (latest)

empty willow
#

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(int argc, const char * argv[]) {
// insert code here...

int x = (rand() % 100)+1;
int y;
int loop=0;
while(loop<1){
    cin>>y;
    if(y==x){
        cout<<"You win!"<<endl;
        loop=1;
    }
    else if (y>x){
        cout<< "Lower"<<endl;
    }
    else if (y<x){
        cout<< "Higher"<<endl;
    }

}
return 0;

}

waxen monolithBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

rich vault
#

And whats the question?

waxen monolithBOT
empty willow
#

sry i wasnt looking at this all

#

it always uses the same number

burnt spear
violet glacierBOT
#
Program Output
1245829513
474198281
1790316611
1125780126
660404363
1497842835
579698543
2145063111
522740060
1921903428
burnt spear
#

¯_(ツ)_/¯

empty willow
#

if you dont mind can you please explain this

#

i just started learning c++ like a month ago

burnt spear
empty willow
#

?

burnt spear
#

the current time is usually a good seed

burnt spear
empty willow
#

what does the time have to do with anything?

burnt spear
#

for a pseudorandom number

#

a random number is just a seed number that has been modified by many operations

empty willow
#

ok so it gives of the illusion of being random while actually being based on the time?

burnt spear
#

and to get a fairly random seed to start off you get the time

burnt spear
#

i mean

#

kinda

#

you need a seed

empty willow
#

thanks

burnt spear
#

A pseudorandom sequence of numbers is one that appears to be statistically random, despite having been produced by a completely deterministic and repeatable process.

empty willow
#

ok

#

btw what does srand mean

burnt spear
#

seedrand (?)

#

idk ¯_(ツ)_/¯

empty willow
#

ok

waxen monolithBOT
empty willow
#

did you tell it to do that?

burnt spear
#

yes

empty willow
#

i heard this is one of the hardest coding languages to learn

empty willow
#

and thats kind of funny to me because in need to learn this before I get to high school for robotics lol

empty willow
burnt spear
empty willow
#

a coding languages?

burnt spear
#

dont worry about it

empty willow
#

ok

#

well thanks for the help!

#

!solved

waxen monolithBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

burnt spear
#

btw

#

there is a whole random generator library for c++, but imo it's fairly complicated to justify using it for something simple

#

but it can do stuff like normal distribution for example

rich vault
burnt spear
violet glacierBOT
#
Program Output
1804289383
846930886
1681692777
1714636915
1957747793
424238335
719885386
1649760492
596516649
1189641421
burnt spear
#

@empty willow basically, if you'd use a constant value it'd give the same sequence

empty willow
#

ok

burnt spear
#

stuff like number of processes running, time, etc are almost never constant