.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   Random_long(0, ??) (http://forums.bots-united.com/showthread.php?t=223)

stefanhendriks 05-01-2004 21:28

Random_long(0, ??)
 
I actually wonder what RANDOM_LONG takes for args.

Is it:

RANDOM_LONG(from, TILL) or RANDOM_LONG(from, including)

meaning:

RANDOM_LONG(0,10) can return 0,1,2,3,4,5,6,7,8,9
or it can return: 0,1,2,3,4,5,6,7,8,9,10

i need to know this because my current function does not seem to return all goals i want, or... it could be i have been darn unfortunate:

Code:

// Find a goal, and return the node close to it
int cNodeMachine::node_goal(int iType)
{
 if (iType == GOAL_NONE)
  return -1;

 int goals_list[MAX_GOALS];
 for (int c=0; c < MAX_GOALS; c++)
  goals_list[c] = -1;

 int iId = 0;
 for (int g=0; g< MAX_GOALS; g++)
  if (Goals[g].iType == iType && Goals[g].iNode > -1)
  {
  goals_list[iId] = Goals[g].iNode;
  iId++;
  }

 if (iId == 0)
  return -1; // nothing found :(

 iId--;
 // we have an amount of goals (iId has them)
// TODO: Is it TILL iId? or INCLUDING? Assuming including now.
 int the_goal = RANDOM_LONG(0, iId);
 
 return goals_list[the_goal];
}


Rick 05-01-2004 21:41

Re: Random_long(0, ??)
 
I think (and especially hope, I use it VERY much) it will include the lowest and highest number. But you can easily find it out just print every frame a random number between 0 and 10 to an file and play about 5 minutes :)

stefanhendriks 05-01-2004 21:57

Re: Random_long(0, ??)
 
yes, i know, i am just to lazy (grtz at pierre ;) ) to put such code in my bot...

koraX 05-01-2004 21:57

Re: Random_long(0, ??)
 
RANDOM_LONG(0,10);

Code:

Random Long from 0 to 10 : 4
Random Long from 0 to 10 : 3
Random Long from 0 to 10 : 5
Random Long from 0 to 10 : 5
Random Long from 0 to 10 : 10
Random Long from 0 to 10 : 4
Random Long from 0 to 10 : 9
Random Long from 0 to 10 : 3
Random Long from 0 to 10 : 6
Random Long from 0 to 10 : 3
Random Long from 0 to 10 : 1
Random Long from 0 to 10 : 4
Random Long from 0 to 10 : 9
Random Long from 0 to 10 : 0
Random Long from 0 to 10 : 9
Random Long from 0 to 10 : 7
Random Long from 0 to 10 : 9
Random Long from 0 to 10 : 10
Random Long from 0 to 10 : 1

o_O

Rick 05-01-2004 22:10

Re: Random_long(0, ??)
 
yay :) all numbers are in the list

Pierre-Marie Baty 05-01-2004 22:19

Re: Random_long(0, ??)
 
else write your own random number generating facility, and don't bother calling functions in the engine for that. I'm considering this with more and more interest, actually :)

koraX 06-01-2004 09:10

Re: Random_long(0, ??)
 
I wanted to ask If RANDOM_LONG (or RANDOM_FLOAT) is better
then using rand() function
(eg. is it faster or is it only to ease programming ?)

botmeister 07-01-2004 06:04

Re: Random_long(0, ??)
 
I agree with what PMB is saying, use as little of the engine as you can. You should try and separate your code from the engine through a clean interface.

I don't know which functions will be better, but my guess is that rand() will be faster to call. The best reason to use your own random_long (etc) is that you can reuse the code for other projects.

For example, I built all my own timing functions and I don't use the engine for timing at all. Now I can use these same functions on other projects which is nice. My code is much cleaner too, and problems that some people had with the engine timing never affected me.

koraX 07-01-2004 07:46

Re: Random_long(0, ??)
 
Quote:

Originally Posted by botmeister
For example, I built all my own timing functions and I don't use the engine for timing at all. Now I can use these same functions on other projects which is nice. My code is much cleaner too, and problems that some people had with the engine timing never affected me.

Have you replaced gpGlobals->time ? And what problems may arise from using it ? 8o

botmeister 07-01-2004 09:04

Re: Random_long(0, ??)
 
Quote:

Originally Posted by koraX
Have you replaced gpGlobals->time ? And what problems may arise from using it ? 8o

Yes, I use my own timing functions based on the function clock( )

I once saw some people had problems over at the botmans forums, but now I can't remember exactly what it was.


All times are GMT +2. The time now is 15:28.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.