Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
random setfreq rather than a static number
Goto page Previous  1, 2
 
Post new topic   Reply to topic Printable version
 View previous topic  A plugin Post :: Post Plugin Request: ASSS style soccer bal...  View next topic  
Author Message
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Thu Oct 21, 2004 11:12 pm    Post subject: Reply to topic Reply with quote

Code: Show/Hide
// Seed random number generator (do once when program starts)
void seedRandom()
{
   srand(time(0));
}

// Get a random number between lowerBound and upperBound, inclusive
// so getRandomNumber(2,4) will return 2, 3, or 4
// if your range is invalid (lowerBound < upperBound) returns -1
int getRandomNumber(int lowerBound, int upperBound)
{
   int range = upperBound - lowerBound + 1;
   int rv = -1;

   if (range > 0)
  {
    rv = lowerBound + rand() % range;
  }
   
  return rv;
}


And make sure in your code you call seedRandom() once when the program starts (or in the botInfo constructor) and use getRandomNumber(2,85); to get a random number between 2 and 85, inclusive.

so like:

sendPrivate(p,"*setfreq " + (String)getRandomNumber(2,85));

where p is a Player*
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:41
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Fri Oct 22, 2004 9:21 am    Post subject: Reply to topic Reply with quote

Code: Show/Hide
// Seed random number generator (do once when program starts)
void seedRandom()
{
   srand(time(0));
}

// Get a random number between lowerBound and upperBound, inclusive
// so getRandomNumber(2,4) will return 2, 3, or 4
// if your range is invalid (lowerBound < upperBound) returns -1
int getRandomNumber(int lowerBound, int upperBound)
{
   int range = upperBound - lowerBound + 1;
   int rv;

   if (range > 0)
    rv = lowerBound + (int)(range * ((float)rand() / RAND_MAX));
   else if (range == 0)
    rv = lowerBound;
   else
     rv = -1;
   
  return rv;
}


A slightly better randomizer. rand() returns with its higher bits more randomizer than its lower bits. So doing 2*(rand()/RAND_MAX) will return an average of 0.5, while rand()%2 may return 0.7 after 1000 trials.
Back to top
View users profile Send private message Add User to Ignore List Send email
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Fri Oct 22, 2004 1:43 pm    Post subject: Reply to topic Reply with quote

Code: Show/Hide
// Stan bak

#include <time.h>
#include <iostream>
#include <stdlib.h>
using namespace std;

#define RUNS 1000000

int main()
{
   int numGreater = 0;
   int numLess = 0;
   int num, x;

   srand((int)time(0));

   for (x = 0; x < RUNS;++x)
   {
      num = rand() % 128;

      if (num >= 64)
         numGreater++;
      else
         numLess++;
   }

   cout << "Num less: " << numLess << endl;
   cout << "Num greater: " << numGreater << endl;

   return 0;
}


Output:

TRIAL 1
Num less: 499908
Num greater: 500191

TRIAL 2
Num less: 500224
Num greater: 499776

TRIAL 3
Num less: 500058
Num greater: 499942

TRIAL 4
Num less: 499350
Num greater: 500650

maybe there's different versions of rand?
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Fri Oct 22, 2004 2:52 pm    Post subject: Reply to topic Reply with quote

Thank you Bak for your sanity in times of chaos (MGB and UL). icon_smile.gif
_________________
4,691 irradiated haggis!
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Fri Oct 22, 2004 5:24 pm    Post subject: Reply to topic Reply with quote

Code: Show/Hide
#include <iostream>

You call that sanity?!
_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Fri Oct 22, 2004 7:02 pm    Post subject: Reply to topic Reply with quote

I was willing to ignore that transgression for the greater good. icon_smile.gif
Back to top
View users profile Send private message Add User to Ignore List
Underlord
Novice


Gender:Gender:Male
Joined: Feb 17 2004
Posts: 55
Offline

PostPosted: Fri Oct 22, 2004 7:31 pm    Post subject: Reply to topic Reply with quote

Code: Show/Hide
The rand() function in the Microsoft C library v4.0.
         Definition:
         SEED = (214013*SEED + 2531011) mod 2**31
   X = int( SEED/2**16 )
   Returns integer in range [0, 2**15)     {0 inclusive, 2**15 exclusive}


that's a normal linear congruential generator.
y = rand() % M; focuses on the lower bits of rand(), so the lower bytes are much less random than the higher bytes. The lowest bit cycles between 0 and 1.

there's different versions of rand(), so need to know which bak is using. should always use the:

(int) (97 * ((float)rand()/RAND_MAX))

way unless you are sure your rand() function is safe

did some tests awhile back on vc++ 6.0 stdlib rand(), it gave chi square distribution 0.01% (<1% = nonrandom), arithmetic mean 52 (127 = random), monte carlo 4 (should be pi)

http://home1.gte.net/deleyd/random/random4.html#CRAND
http://www.fourmilab.ch/random/

bigshot: long as u do srand then either rand() method, u should be fine. don't need super random numbers for a freq changing bot. post your source if you still can't get it to work
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
50% Packetloss
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Sep 09 2003
Posts: 561
Location: Santa Clarita, California
Offline

PostPosted: Fri Oct 22, 2004 9:23 pm    Post subject: Reply to topic Reply with quote

Just hook your bot up to this random number generator
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Fri Oct 22, 2004 9:39 pm    Post subject: Reply to topic Reply with quote

How random "random" really is doesn't matter in this case. It's not like he's using this for encryption.
_________________
Hyperspace Owner

Smong> so long as 99% deaths feel lame it will always be hyperspace to me
Back to top
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 93 page(s) served in previous 5 minutes.

phpBB Created this page in 0.511056 seconds : 33 queries executed (79.3%): GZIP compression disabled