Jump to content

Help me with the usage of rand() function

- - - - -

  • Please log in to reply
3 replies to this topic

#1
klavus

klavus

    Newbie

  • Members
  • Pip
  • 2 posts
Hello!
Is there any way to use the rand() function properly to give me the results i want between the max and min limit numbers i set?
For example i want to print random numbers between 500 and 1000.

Till now the only usage of rand() i know is to randomize numbers between 0 and the max limit i will choose
rand()%1000 (it gives numbers from 0 to 1000)

Is there any idea/solution about that?

Thank you in advance!!

#2
Ancient Dragon

Ancient Dragon

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 400 posts
I think this thread will give you the solution you are looking for.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.

#3
lintwurm

lintwurm

    Learning Programmer

  • Members
  • PipPipPip
  • 77 posts
I don't know what the thread says, but if you do (rand()%500) + 500; then it will give you a random number between 500 and 1000?
^_^
If this is not right, I apologize for the waste of time

#4
klavus

klavus

    Newbie

  • Members
  • Pip
  • 2 posts

Ancient Dragon said:

I think this thread will give you the solution you are looking for.

I found something in the thread you linked and i think it might help !Thanks dude!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users