.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Bot Coding
General Bot Coding See what a pain it is to get those little mechs shooting around

Reply
 
Thread Tools
Random_long(0, ??)
Old
  (#1)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Random_long(0, ??) - 05-01-2004

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];
}


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: Random_long(0, ??)
Old
  (#2)
Rick
Council Member
 
Rick's Avatar
 
Status: Offline
Posts: 690
Join Date: Dec 2003
Location: Holland
Default Re: Random_long(0, ??) - 05-01-2004

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
  
Reply With Quote
Re: Random_long(0, ??)
Old
  (#3)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: Random_long(0, ??) - 05-01-2004

yes, i know, i am just to lazy (grtz at pierre ) to put such code in my bot...


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: Random_long(0, ??)
Old
  (#4)
koraX
Member
 
koraX's Avatar
 
Status: Offline
Posts: 145
Join Date: Jan 2004
Location: Slovak Republic
Default Re: Random_long(0, ??) - 05-01-2004

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


kXBot
koraX's utils
- see my homepage for other projects (OpenGL CSG Editor, FAT16 Sim, NNetwork Sim, ...)
  
Reply With Quote
Re: Random_long(0, ??)
Old
  (#5)
Rick
Council Member
 
Rick's Avatar
 
Status: Offline
Posts: 690
Join Date: Dec 2003
Location: Holland
Default Re: Random_long(0, ??) - 05-01-2004

yay all numbers are in the list
  
Reply With Quote
Re: Random_long(0, ??)
Old
  (#6)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: Random_long(0, ??) - 05-01-2004

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



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: Random_long(0, ??)
Old
  (#7)
koraX
Member
 
koraX's Avatar
 
Status: Offline
Posts: 145
Join Date: Jan 2004
Location: Slovak Republic
Default Re: Random_long(0, ??) - 06-01-2004

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 ?)


kXBot
koraX's utils
- see my homepage for other projects (OpenGL CSG Editor, FAT16 Sim, NNetwork Sim, ...)
  
Reply With Quote
Re: Random_long(0, ??)
Old
  (#8)
botmeister
Ex-Council Member
 
botmeister's Avatar
 
Status: Offline
Posts: 1,090
Join Date: Nov 2003
Location: Canada
Default Re: Random_long(0, ??) - 07-01-2004

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.


Maker of the (mEAn) Bot.Admin Manager

"In theory, there is no difference between theory and practice. But, in practice, there is." - Jan L.A. van de Snepscheut
  
Reply With Quote
Re: Random_long(0, ??)
Old
  (#9)
koraX
Member
 
koraX's Avatar
 
Status: Offline
Posts: 145
Join Date: Jan 2004
Location: Slovak Republic
Default Re: Random_long(0, ??) - 07-01-2004

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


kXBot
koraX's utils
- see my homepage for other projects (OpenGL CSG Editor, FAT16 Sim, NNetwork Sim, ...)
  
Reply With Quote
Re: Random_long(0, ??)
Old
  (#10)
botmeister
Ex-Council Member
 
botmeister's Avatar
 
Status: Offline
Posts: 1,090
Join Date: Nov 2003
Location: Canada
Default Re: Random_long(0, ??) - 07-01-2004

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.


Maker of the (mEAn) Bot.Admin Manager

"In theory, there is no difference between theory and practice. But, in practice, there is." - Jan L.A. van de Snepscheut
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com