Get a random between 2 numbers

Talk about making games.

Re: Get a random between 2 numbers

Postby Bee-Ant » Sat Jul 10, 2010 5:57 pm

@lcl:
Bee-Ant wrote:
Code: Select all
float GetRandomBetween(float ii,float jj)
{
    float ij=rand(max(ii,jj)-min(ii,jj));
    return ij+min(ii,jj);
}


With this code, you can return any number between any number.
If you want to return a number between negative with positive then just type:
Code: Select all
textNumber=GetRandomBetween(-5,5); //or
textNumber=GetRandomBetween(5,-5);

Please try first before you ask :D
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Get a random between 2 numbers

Postby Hblade » Sat Jul 10, 2010 5:59 pm

Yeah :3
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Get a random between 2 numbers

Postby lcl » Sat Jul 10, 2010 10:31 pm

Oh... :oops: sorry.
Good work! :D I didn't understand nearly anything about your code... :shock:
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Get a random between 2 numbers

Postby Scorpion50o1 » Fri Aug 13, 2010 6:25 am

hey could we make a little dice rolling game or quarter flipping thing outta this?
OMG IM SO BORED <(^^)> (>^^)> (>^^)>
92% of teens have moved on to rap. If you are part of the 8% who still listen to real music, copy and paste this into your signature.
User avatar
Scorpion50o1
 
Posts: 246
Joined: Fri Apr 17, 2009 1:07 am
Location: TX
Score: 8 Give a positive score

Re: Get a random between 2 numbers

Postby TSO » Tue Sep 28, 2010 10:51 pm

I can't seem to get any of these to work and all I need is a random number of 1 or 2 in a variable I can check.
TSO
 
Posts: 87
Joined: Thu Sep 02, 2010 5:53 pm
Score: 4 Give a positive score

Previous

Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron