Page 1 of 1

How do I?

Posted: Sun Apr 05, 2009 10:29 pm
by RandomDever
Make a C++ Debug Prompt?
Is it possible?
:shock:

Re: How do I?

Posted: Mon Apr 06, 2009 12:25 am
by Falco Girgis
No. Not without having a C++ compiler/interpreter going in real-time.

It would be infinitely more easy to make an in-game assembly debug prompt. It would be an extremely platform specific endeavor, but it's very possible to do it on anything (Dreamcast even).

Re: How do I?

Posted: Mon Apr 06, 2009 12:55 am
by RandomDever
Thanks for the reply. :mrgreen:
BTW What about a random number generator function that would take the minimum and maximum number it could genereate?

Re: How do I?

Posted: Mon Apr 06, 2009 7:09 am
by Falco Girgis
rand() and being a little bit of a smartass will work.

Code: Select all

rand()%number+min
Where number is equal to min+number of random numbers = max random number.

So if you want 10-20 randomly:

Code: Select all

rand()%10+10

Re: How do I?

Posted: Mon Apr 06, 2009 9:24 am
by avansc

Code: Select all

int random_range(int min, int max)
{
    return rand()%(max-min)+min;
}

personally i would make it like this.

Code: Select all

double random(double min, double max)
{
	return (rand()/((double)(RAND_MAX)+1.0))*(max-min)+min;
}
that way you get a double back. its not better. its just nice when you need a random number with a bit more "meaning"
you can just use an int case on the call if you just need an int value.

(int)random(lower, upper);

anyways.

Re: How do I?

Posted: Mon Apr 06, 2009 12:32 pm
by Falco Girgis
Thanks, avansc. I had a hard time putting what I meant into words. Your first function is exactly what I was trying to say.

Re: How do I?

Posted: Mon Apr 06, 2009 1:26 pm
by RandomDever
Thanks guys the random_range function works perfectly.
Sweet! :mrgreen:
Edit: Now back to work Image