.:: 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
Re: Portable, self-contained replacements for RANDOM_STUFF()
Old
  (#21)
botmeister
Ex-Council Member
 
botmeister's Avatar
 
Status: Offline
Posts: 1,090
Join Date: Nov 2003
Location: Canada
Default Re: Portable, self-contained replacements for RANDOM_STUFF() - 08-01-2004

You can use a seed derived from the system clock, that way each time your comupter app runs, it will use a different seed.


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: Portable, self-contained replacements for RANDOM_STUFF()
Old
  (#22)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default Re: Portable, self-contained replacements for RANDOM_STUFF() - 14-04-2006

this is related with this thread, so instead opening a new one, just posting here.

well here is my implemention of random generator derived from an article in "Game Programming Gems", with a bit improvement, which is less "twisted" but random enough I guess:

PHP Code:
static long glSeed 0glGen2 0glGen1 0// our random number generator's seed

/**
 * This function initializes the random seed based on the initial seed value pass in the
 * initial_seed parameter.
 */
void lsrand(unsigned long initial_seed)
{
   
// Pick two large integers such that one is double the other
   
glGen2 3719;
   
glGen1 glGen2 2;

   
// fill in the initial seed of the random number generator
   
glSeed = (glGen1 initial_seed) + glGen2;
}

/**
 * This function is the equivalent of the rand() standard C library function, except that
 * whereas rand() works only with short integers (i.e. not above 32767), this f$
 * able to generate 32-bit random numbers. Isn't that nice?
 */
long lrand(void)
{
   if (
glSeed == 0// if the random seed isn't initialized...
      
lsrand(time(NULL)); // initialize it first
   
glSeed = (glGen1 glSeed) + glGen2// do some twisted math
   
return glSeed glSeed : -glSeed// and return absolute value of the result
}

/**
 * This function returns a random integer number between (and including) the starting and
 * ending values passed by parameters from and to.
 */
long RandomLong(long fromlong to)
{
   if (
to <= from)
      return 
from;

   return 
from lrand() / (LONG_MAX / (to from 1));
}

/**
 * This function returns a random floating-point number between (and including) the starting
 * and ending values passed by parameters from and to.
 */
long RandomLong(long fromlong to)
{
   if (
to <= from)
      return 
from;

   return 
from + (float)lrand() / (LONG_MAX / (to from));

btw, as long as the PDF spec. and free pdf viewers like xpdf are publically available (gv is also able to open pdf file), there is not problem to use the pdf format and it still sucks less than e.g., .doc format (except its DRM "features")...

Last edited by Whistler; 14-04-2006 at 11:24..
  
Reply With Quote
Reply


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

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