Jump to content
fancoelho

Gerar numero aleatorio

Recommended Posts

fancoelho

Boa tarde..Gostava de saber que funcao usar em c++, para gerar um numero entre x e y definidos por mim e usar depois em outra função.

Agradeço a ajuda..

Obrigado

Share this post


Link to post
Share on other sites
Diutsu

tens de usar o random e depois manipulas o resultado

  /* initialize random seed: */
  srand ( time(NULL) );

// assert(x<y);
  /* generate secret number: */
  number = rand() % (y-x) + 1 + x;


XX SINFO - Semana Informática

Share this post


Link to post
Share on other sites
Baderous

sim

stdlib.h para o rand e time.h para o time

Uma vez que estamos em C++, serão as bibliotecas <cstdlib> e <ctime>.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.