I saw an article on the new game "State of Emergency", and noticed how advanced the AI was (it's kinda like GTA3, cept killing pedestrians is the point, and the crowds react to gunshots, people dying, etc.), it could control 500 people at a time. So I decided to try it with simple squares that react to a simlated gunshot. Space starts the simulation, and return stops it. The problem is, everyone moves similarly, and I tried added a random factor to it, but rand() relies on the system clock, which doesn't change much during a for loop. I also need some sort of collision system (simple rectangle bounding box) so they won't run into each other. Here's the Allegro code(sorry, but ftp isn't working quite right, so I hafta c/p):

Code:
#include <allegro.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define RX 640
#define RY 480
#define STILL 0
#define UP 1
#define DOWN 2
#define LEFT 3
#define RIGHT 4

void randomize() {
 srand((unsigned)time(NULL));
}

int rand(int num) {
 randomize();
 return rand()%num;
}

class square {
 public:
  int size;
  int x, y;
  int c;
  int speed, brave;
  int dir;
  bool run;
  void move(int mx, int my);
};

void square::move(int mx, int my) {
 x = x + mx;
 y = y + my;
}

int main() {
 int n, cury = 230, curx = 100, scare = 10;
 allegro_init();
 set_gfx_mode(GFX_AUTODETECT_WINDOWED, RX, RY, 0, 0);
 set_window_title("Crowd Control");
 set_color_depth(8);
 install_mouse();
 install_keyboard();
 set_palette(default_palette);
 BITMAP *screen2 = create_video_bitmap(RX, RY), *buffer = create_bitmap(RX, RY);
 fade_in(default_palette, 1);
 square player, crowd[10];
 player.x = 10;
 player.y = 230;
 player.c = 4;
 player.size = 10;
 player.dir = STILL;
 player.run = false;
 player.speed = 3;
 for (n=0;n<10;n++) {
  crowd[n].size = 10;
  curx += 30;
  crowd[n].x = curx;
  crowd[n].y = cury;
  crowd[n].c = 1;
  crowd[n].brave = 5;
  crowd[n].speed = 1;
  crowd[n].dir = STILL;
  crowd[n].run = false;
 }
 while(!key[KEY_ESC]) {
  clear_bitmap(buffer);
  if (key[KEY_UP]) {
   player.dir = UP;
   player.y -= player.speed;
  }
  if (key[KEY_DOWN]) {
   player.dir = UP;
   player.y += player.speed;
  }
  if (key[KEY_LEFT]) {
   player.dir = UP;
   player.x -= player.speed;
  }
  if (key[KEY_RIGHT]) {
   player.dir = UP;
   player.x += player.speed;
  }
  if (key[KEY_SPACE]) {
   for (n=0;n<10;n++) {
    crowd[n].run = true;
   }
  }
  if (key[KEY_ENTER]) {
   for (n=0;n<10;n++) {
    crowd[n].run = false;
   }
  }
  for (n=0;n<10;n++) {
   if (crowd[n].run == true) {
    if (scare > crowd[n].brave) {
     if (crowd[n].x > player.x || rand(3) == 1) {
      crowd[n].x = crowd[n].x + (rand(2) + crowd[n].speed);
     }
	 if (crowd[n].x < player.x || rand(3) == 1) {
	  crowd[n].x = crowd[n].x - (rand(2) + crowd[n].speed);
	 }
	 if (crowd[n].y > player.y || rand(3) == 1) {
	  crowd[n].y = crowd[n].y + (rand(2) + crowd[n].speed);
	 }
	 if (crowd[n].y < player.y || rand(3) == 1) {
	  crowd[n].y = crowd[n].y - (rand(2) + crowd[n].speed);
	 }
    }
   }
  }
  rectfill(buffer,player.x,player.y,player.x+player.size,player.y+player.size,player.c);
  for (n=0;n<10;n++) {
   rectfill(buffer,crowd[n].x,crowd[n].y,crowd[n].x+crowd[n].size,crowd[n].y+crowd[n].size,crowd[n].c);
  }
  blit(buffer, screen2, 0, 0, 0, 0, RX, RY);
  show_video_bitmap(screen2);
 }
 fade_out(6);
 allegro_exit();
 return 0;
}

END_OF_MAIN();

Thanks for any help,
Scott Hand