Exemplo n.º 1
0
void* producer(void *ptr) {
	int i;
	int wait;  
	while(1) {
		   wait = (genrand_int32() % 5) + 3;
		   sleep(wait);
		   pthread_mutex_lock(&control);
		   while(bufferLength == (MAX)){
			      printf("Waiting for consumer... \n");
			      pthread_cond_wait(&conditionalProd, &control);	
		   }	
		   buffer[bufferLength].wait = (genrand_int32() % 8) + 2; 
		   buffer[bufferLength].value = genrand_int32() % 100; 
		   bufferLength++;
		   printf("Producer: Produced item with value %d. Buffer at %d \n", buffer[bufferLength-1].value, bufferLength);
		   pthread_cond_signal(&conditionalCons); 
		   pthread_mutex_unlock(&control); 
	}
	pthread_exit(0);
}
Exemplo n.º 2
0
int* makeArray( int size ) {
	unsigned long init[4] = { 0x123, 0x234, 0x345, 0x456 };
	unsigned long length = 10;
	init_by_array( init, length );
	int*array = ( int* )malloc( sizeof(int) * size );
	if( !array )
		return NULL;
	int*p = array;
	for( int i = 0; i < size; i++ )
		*p++ = abs( (int) genrand_int32() >> 16 );
	return array;
}
Exemplo n.º 3
0
void _encrypt(char * pBuffer, size_t size, size_t seed )
{
	// 加密
	s_mersenne_twister_status mt;
	size_t i;
	unsigned long rseed = (seed << 7) ^ 0xA9C36DE1;
	init_genrand(&mt, rseed);
	for (i = 0; i < size;i++)
	{
		pBuffer[i] = (char)(pBuffer[i]  ^ genrand_int32(&mt));
	}
}
Exemplo n.º 4
0
static void
prepareNoiseRect(SVGASignedPoint *origin)  // OUT
{
   const uint32 bytesPerLine = 1024;
   static const SVGAGMRImageFormat format = {{{ 32, 24 }}};
   const SVGAGuestPtr gPtr = { GMRID_NOISE, 0 };
   const uint32 rand = genrand_int32();

   Screen_DefineGMRFB(gPtr, bytesPerLine, format);

   origin->x = rand & 0x7F;
   origin->y = (rand >> 8) & 0x7F;
}
Exemplo n.º 5
0
//Generate random numbers
int gen_number(int high, int low) {

    int num = 0;

    num = (int)genrand_int32();
    num = abs(num);
    num %= (high - low);
    if (num < low)
    {
        num = low;
    }

    return num;
}
Exemplo n.º 6
0
void init_extra_data(void){
  static int done = 0;
  int i;

  if(done)
    return;

  init_genrand(0);

  for( i = 0 ; i < EXTRA_BYTE; i++)
    extra_data[i] = (char) genrand_int32() % 256;

  done = 1;
}
Exemplo n.º 7
0
bool Th105DataArchiveExtractor::header_crypt_impl(std::vector<unsigned char> &data, unsigned long mt_seed, unsigned char a, unsigned char b, unsigned char c) {
	if(data.empty()){
		return true;
	}
	unsigned char * p = &data.front();
	init_genrand(mt_seed);
	while(p <= &data.back()){
		*p ^= genrand_int32() ^ a;
		a += b;
		b += c;
		++p;
	}
	return true;
}
Exemplo n.º 8
0
//__________________________________________________________________________________
_PMathObj _Constant::Random (_PMathObj upperB)
{
    if (randomCount == 0) {
        randomCount++;
    }
    _Parameter l = theValue, u=((_Constant*)upperB)->theValue,r = l;
    if (u>l) {
        r=genrand_int32();
        r/=RAND_MAX_32;
        r =l+(u-l)*r;
    }
    return new _Constant (r);

}
Exemplo n.º 9
0
int main(int argc, char *argv[]) {

  // Disable IO buffering
  setbuf(stdin, NULL);
  setbuf(stdout, NULL);
  std::cout.rdbuf()->pubsetbuf(NULL, 0);
  std::cin.rdbuf()->pubsetbuf(NULL, 0);

  // Initialization

  init_mersenne();
  init_direction_table();
  init_bitboards();
  init_uci_options();
  Position::init_zobrist();
  Position::init_piece_square_tables();
  MaterialInfo::init();
  MovePicker::init_phase_table();
  init_eval(1);
  init_bitbases();
  init_threads();

  // Make random number generation less deterministic, for book moves
  int i = abs(get_system_time() % 10000);
  for(int j = 0; j < i; j++)
    genrand_int32();

  // Process command line arguments
  if(argc >= 2) {
    if(std::string(argv[1]) == "bench") {
      if(argc != 4) {
        std::cout << "Usage: glaurung bench <hash> <threads>" << std::endl;
        exit(0);
      }
      benchmark(std::string(argv[2]), std::string(argv[3]));
      return 0;
    }
  }

  // Print copyright notice
  std::cout << engine_name() << ".  "
            << "Copyright (C) 2004-2008 Tord Romstad."
            << std::endl;

  // Enter UCI mode
  uci_main_loop();

  return 0;
}
Exemplo n.º 10
0
void ThrowClientHead (edict_t *self, int damage)
{
	vec3_t	vd;
	char	*gibname;

	if (genrand_int32()&1)
	{
		gibname = "models/objects/gibs/head2/tris.md2";
		self->s.skinnum = 1;		// second skin is player
	}
	else
	{
		gibname = "models/objects/gibs/skull/tris.md2";
		self->s.skinnum = 0;
	}

	self->s.origin[2] += 32;
	self->s.frame = 0;
	gi.setmodel (self, gibname);
	VectorSet (self->mins, -16, -16, 0);
	VectorSet (self->maxs, 16, 16, 16);

	self->takedamage = DAMAGE_NO;
	self->solid = SOLID_NOT;
	self->s.effects = EF_GIB;
	self->s.sound = 0;
	self->flags |= FL_NO_KNOCKBACK;

	//this fixes heads floating in air, i hope!
	self->clipmask = MASK_SOLID;
	self->groundentity = NULL;

	self->movetype = MOVETYPE_BOUNCE;
	VelocityForDamage (damage, vd);
	VectorAdd (self->velocity, vd, self->velocity);

	if (self->client)	// bodies in the queue don't have a client anymore
	{
		self->client->anim_priority = ANIM_DEATH;
		self->client->anim_end = self->s.frame;
	}
	else
	{
		self->think = NULL;
		self->nextthink = 0;
	}

	gi.linkentity (self);
}
Exemplo n.º 11
0
void picksite_ero()                 // pick a site to erode from
{
    // first sample a random location
    int i = genrand_int32() % nrows;
    int j = genrand_int32() % ncols;
    /*
	Conditions for erosion:
        1) surface higher than basement
        2) surface higher or equal to shadow (e.g., not in a shadow zone)
    Notes:
    This function is an if statement, rather than a while loop to allow
    time to pass properly. If the conditions are assessed as part of a
    while loop, time stands unnaturally still searching for a site for erosion.
    */
    if ((surf[i][j] > bsmt[i][j]) && (surf[i][j] >= shad[i][j]))
    {
        i_ero = i; j_ero = j;   // if conditions are met, set the erosion coordinates
        ero_flag = true;        // set the flag high
    }
    else
    {
        ero_flag = false;       // else, no erosion this time, flag is low
    }
}
Exemplo n.º 12
0
bool CItemManager::SaveItem(CItem *item, uint32 slot)
{
	QSqlQuery q(accounts_db.db);
	bool result = false;
	switch(item->status)
	{
	case ITEM_CHANGED:
		{
			accounts_db.LockForWrite();
			result = q.exec(Query("UPDATE `character_items` SET `slot` = %u, `type` = %u, `level` = %u, `durability` = %f, `option1` = %u, `option2` = %u, `option3` = %u, `newoption` = %u, `setoption` = %u, `petitem_level` = %u, `petitem_exp` = %u, `joh_option` = %u, `optionex` = %u WHERE `dbuid` = %u;", slot, item->type, item->level, item->durability, item->option1, item->option2, item->option3, item->option_new, item->m_SetOption, item->m_PetItem_Level, item->m_PetItem_Exp, item->m_JewelOfHarmonyOption, item->m_ItemOptionEx, item->dbuid).c_str());
			accounts_db.Unlock();
			item->status = ITEM_UNCHANGED;
			break;
		}
	case ITEM_NEW:
		{
			init_genrand(GetTicks());
			accounts_db.LockForWrite();
			uint32 ncount = 0;
			uint32 temp_dbuid = 0;
			while(ncount < RETRIES)
			{
				++ncount;
				temp_dbuid = genrand_int32();
				result = q.exec(Query("SELECT `id` FROM `character_items` WHERE `dbuid` = %u;", temp_dbuid).c_str());
				assert(result);
				if(!q.next())
				{
					break;
				}
			}
			assert(ncount != 0x0fffffff);
			item->dbuid = temp_dbuid;
			result = q.exec(Query("INSERT IGNORE INTO `character_items` (`dbuid`, `slot`, `type`, `level`, `durability`, `option1`, `option2`, `option3`, `newoption`, `setoption`, `petitem_level`, `petitem_exp`, `joh_option`, `optionex`) VALUES (%u, %u, %u, %u, %f, %u, %u, %u, %u, %u, %u, %u, %u, %u);", item->dbuid, slot, item->type, item->level, item->durability, item->option1, item->option2, item->option3, item->option_new, item->m_SetOption, item->m_PetItem_Level, item->m_PetItem_Exp, item->m_JewelOfHarmonyOption, item->m_ItemOptionEx).c_str());
			assert(result);
			item->status = ITEM_UNCHANGED;
			accounts_db.Unlock();
		}
	default:
		break;
	}
	if(!result)
	{
		Log.String("Save item %u db: %u failed: %u.", item->guid, item->dbuid, q.lastError().type());
		return false;
	}
	return true;
}
Exemplo n.º 13
0
static void
allocNoise(void)
{
   const uint32 numPages = 500;
   const uint32 numWords = numPages * PAGE_SIZE / sizeof(uint32);

   PPN pages = GMR_DefineContiguous(GMRID_NOISE, numPages);
   uint32 *ptr = PPN_POINTER(pages);
   int i;

   init_genrand(0);

   for (i = 0; i < numWords; i++) {
      ptr[i] = genrand_int32();
   }
}
Application::Application() {

    init_mersenne();
    init_direction_table();
    init_bitboards();
    init_uci_options();
    Position::init_zobrist();
    Position::init_piece_square_tables();
    init_eval(1);
    init_bitbases();
    init_search();
    init_threads();

    // Make random number generation less deterministic, for book moves
    for (int i = abs(get_system_time() % 10000); i > 0; i--)
        genrand_int32();
}
int main() {
	init_genrand(0);

	uint32_t ain[100];
	hls::stream<uint32_t> din;
	hls::stream<float> dout;

	for (int i = 0; i < 100; ++i) {
		uint32_t rn = genrand_int32();;
		ain[i] = rn;
		din.write(rn);
	}

	float aout[100];
	for (int i = 0; i < 100/2; ++i) {
		float u1 = to_float(ain[2 * i]);
		float u2 = to_float(ain[2 * i + 1]);
		box_muller(u1, u2);
		aout[2 * i] = u1;
		aout[2 * i + 1] = u2;
	}

	gauss_transform(din, dout);

	if (dout.size() != 100) {
		std::cout << "wrong size" << std::endl;
		return -1;
	}

	for (int i = 0; i < 100; ++i) {
		float hw = dout.read();
		float sw = aout[i];
		std::cout << i << ": \t" << hw << " \t(hw) - (sw) " << sw <<
				std::endl;
		if (!(std::isfinite(hw) and std::isfinite(sw) and
				std::abs(hw - sw) < 1E-4)) {
			std::cout << "ERROR: " << i << ": \t" << hw << " \t(hw|sw) "
					<< sw << std::endl;
			return -1;
		}
	}

	std::cout << "passed." << std::endl;
	return 0;
}
Exemplo n.º 16
0
GUID_HIGH CObjectManager::CreateGuid()
{
	init_genrand(GetTicks());
	GUID_HIGH guid = 0;
	uint32 count = 0;
	while(count < RETRIES)
	{
		count++;
		guid = GUID_HIGH(genrand_int32());
		MapType::iterator it = this->container.find(guid);
		if(it == this->container.end())
		{
			break;
		}
	}
	assert(count != RETRIES);
	return guid;
}
Exemplo n.º 17
0
    PerlinField2D(int seed, int _xs, int _grad_max)
    {
        xs = _xs;
        xsize = map_dim.x / xs;
        ssize = xsize*xsize;
        grad_max = _grad_max;
        xscale = 1.0 / ((float) xs);

        seed_twister(seed);

        ga = new unsigned char[ssize];
        for (int i=0; i<ssize; i++)
        {
            ga[i] = genrand_int32() % grad_max; //gradient number
        }
        grad = new float[2*grad_max];
        generate_gradient_vectors();
    }
Exemplo n.º 18
0
        void calc_new_sequence () {
            /* method to set out a new sequence of random samples, without replacement
            */
            int r;              // the coordinate to shuffle
            int rval;           // the value to shuffle
            
            for (int i = len - 1; i > -1; i--) {
                r = genrand_int32() % (i + 1);              // draw a random integer
                rval = vcoords[r];                          // get the value
                vcoords[r] = vcoords[i];                    // shuffle  
                vcoords[i] = rval;                          // shuffle
            }

            // apply the shuffled vcoords to the lookup arrays
            for (int i = 0; i < len; i++) {
                xs[i] = vcoords[i] / ydim;
                ys[i] = vcoords[i] % ydim;
            }
        }
Exemplo n.º 19
0
// Initialise the _population matrix with an array given in parameter
// num: the size of the int* array
// init[month][number of rabbits this month]
void Simulation::Start( const char * outputFileName, int time, int num, int * init[2] ) {
	clock_t startBegin;
	clock_t startEnd;
	_file = fopen( outputFileName, "w+");
    
    startBegin = clock(  );
	if( init != NULL ) {
		for( int i = 0; i < num; ++i ) {
			for( int j = 0; j < init[ i ][ 1 ]; ++j ) {
				// First we determine if rabbits are mature or not
				if( init[ i ][ 0 ] >= 5 && init[ i ][ 0 ] < 8 ) {
					// 80% chance being mature between 5 and 8 month
					if( genrand_int32(  ) % 10 > 1 ) (*_pt)->set_mature( true );
				} // At the 8th month, all rabbits are matures
				else if( init[ i ][ 0 ] >= 8 ) (*_pt)->set_mature( true );
				// If none of this cases, the rabbit is not mature
				else (*_pt)->set_mature( false );
				// Finaly, rabbits are put in the right list and removed from the pool
				_population[ init[ i ][ 0 ] ]->push_back( *_pt );
				*_pt = NULL;
				if( _pt > _pool ) --_pt;
			}
		}
	}
	else {
		for( int i = 0; i < num; ++i ) {
			// All rabbits have 8 months, and are mature so
			(*_pt)->set_mature( true );
			// Rabbits are stored in the month 8 <=> block 7
			( _population[ 7 ] )->push_back( *_pt );
			*_pt = NULL;
			if( _pt > _pool ) --_pt;
			
			// // std::cout << "A rabbit is created" << std::endl;
		}
	}
	// Simulation is launched when everything is ready
	std::cout << "Result " << MonthSimul( time ) << std::endl;
	
	startEnd = clock(  );
	fprintf( _file, "%ld\t%f\n", (long) ( startEnd - startBegin ), (double) ( startEnd - startBegin ) / CLOCKS_PER_SEC );
}
Exemplo n.º 20
0
int Random::nextInt(int max)
{
	return genrand_int32();
	/*
	long unsigned int rand = genrand_int32();
	long unsigned int multiplier = 0x6C078965;
	long unsigned int retval;

	long unsigned int top = (((uint64_t)(rand * multiplier)) & 0xFFFFFFFF00000000) >> 32;
	retval = rand - top;
	retval = (top + (retval >> 1)) >> 4;
	retval += retval << 1;
	retval = retval >> (retval << 3);
	retval = rand - retval;

	if(retval > max)
		retval = max;

	return retval;*/
}
Exemplo n.º 21
0
void init_world() {
	lcdMainOnBottom();

#ifndef NATIVE
	// TODO: replace with gettimeofday() or similar
	init_genrand(genrand_int32() ^ (IPC->time.rtc.seconds +
				IPC->time.rtc.minutes*60 + IPC->time.rtc.hours*60*60 +
				IPC->time.rtc.weekday*7*24*60*60));
#else
	{
		struct timeval tv;
		gettimeofday(&tv,NULL);
		init_genrand(tv.tv_usec+tv.tv_sec*1000000);
	}
#endif

	new_game();

	torch.run(handler);
}
Exemplo n.º 22
0
//{{{void generate_interval_sets(struct interval *A,
// must run init_genrand(seed) first
void generate_interval_sets(struct interval *A,
							unsigned int size_A,
							unsigned int len_A,
							struct interval *B,
							unsigned int size_B,
							unsigned int len_B,
							unsigned int P)
{

	int i;

    for (i = 0; i < size_A; i++) {
		A[i].start = genrand_int32();
		A[i].end = A[i].start + len_A;
	}
	
	qsort(A, size_A, sizeof(struct interval), compare_interval_by_start); 
	
	/*
	 * Draw a number to see if the next interval will intersect or not.
	 * Draw a number to get the next interval, make new interval intersect or
	 * not with the drawn interval based on the first draw.
	 */
	int p_max = 100;
	unsigned int p_mask = get_mask(p_max);
	unsigned int i_mask = get_mask(size_A);
	unsigned int l_mask = get_mask(len_A);

    for (i = 0; i < size_B; i++) {
		unsigned int next_i = get_rand(size_A, i_mask);
		unsigned int next_p = get_rand(p_max, p_mask);

		if (P >= next_p) // intersect
			// Pick an rand between start and end to start from
			B[i].start = A[next_i].start + get_rand(len_A, l_mask);
		else  // do not intersect
			B[i].start = A[next_i].end + get_rand(len_A, l_mask);

		B[i].end = B[i].start + len_B;
	}
}
Exemplo n.º 23
0
static int l_random_rnd(lua_State *L)
{
	uint32_t a, b, r;
	MT *m = l_checkRandom(L, 1);

	r = genrand_int32(m);

	switch (lua_gettop(L)) {
	case 1:
		lua_pushnumber(L, r);
		return 1;
	case 2:
		a = 1;
		b = luaL_checkint(L, 2);
		break;
	case 3:
		a = luaL_checkint(L, 2);
		b = luaL_checkint(L, 3);
		break;
	}

	if (a > b) { 
		int t = a;
		a = b;
		b = t;
	}

#if 0
	a = ceil(a);
	b = floor(b);
#endif

	if (a > b)
		return 0;

	r = a + (r % (b - a + 1));

	lua_pushnumber(L, r);

	return 1;
}
Exemplo n.º 24
0
unsigned int
Simulator::sequential_random_simulation(const BaseVrp& vrp, Solution& solution)
{
    Vehicle *current_vehicle = solution.current_vehicle();
    int candidates[200], candidate_size;

    while (!solution.is_finish())
    {
        candidate_size = 0;

        /* 次に訪問する顧客の候補を求める */
        for (unsigned int i=1; i <= vrp.customer_size(); i++)
        {
            /* 訪問可能であれば候補に追加 */
            if (!solution.is_visit(i) &&
                current_vehicle->capacity() + vrp.demand(i) <= vrp.capacity())
            {
                candidates[candidate_size++] = i;
            }
        }

        if (candidate_size == 0)
        {
            /* 候補がいなければ次の車両へ */
            solution.change_vehicle();
            current_vehicle = solution.current_vehicle();
        }
        else
        {
            /* 候補の中から無作為に1人選ぶ */
            unsigned long r = genrand_int32();
            int customer = candidates[(unsigned int)r % candidate_size];
            current_vehicle->visit(vrp, customer);
        }
    }

    if (solution.is_feasible())
        return solution.compute_total_cost(vrp);
    else
        return 0;
}
Exemplo n.º 25
0
int main(void)
{
    int i;
    unsigned long init[4]={0x123, 0x234, 0x345, 0x456}, length=4;
    init_by_array(init, length);
    /* This is an example of initializing by an array.       */
    /* You may use init_genrand(seed) with any 32bit integer */
    /* as a seed for a simpler initialization                */
    printf("1000 outputs of genrand_int32()\n");
    for (i=0; i<1000; i++) {
      printf("%10lu ", genrand_int32());
      if (i%5==4) printf("\n");
    }
    printf("\n1000 outputs of genrand_real2()\n");
    for (i=0; i<1000; i++) {
      printf("%10.8f ", genrand_real2());
      if (i%5==4) printf("\n");
    }

    return 0;
}
Exemplo n.º 26
0
/***************************************************************************
* Name  : SelectNode
* Brief : 定石の変化度によって候補手を決定する
* Return: 定石番号
****************************************************************************/
BookData *select_node(UINT32 change)
{
	BookData *ret = NULL;

	sort_book_node(g_bookList, g_booklist_cnt);

	if (change == NOT_CHANGE)
	{
		ret = &g_bookList[0];
	}
	else if (change != CHANGE_RANDOM) // err = 5%〜20%
	{
		ret = extract_booklist(g_bookList, g_err_rate, g_booklist_cnt);
	}
	else // full random
	{
		ret = &g_bookList[genrand_int32() % g_booklist_cnt];
	}

	return ret;
}
Exemplo n.º 27
0
/***************************************************************************
* Name  : extract_booklist
* Brief : 誤差によるノード選択
****************************************************************************/
BookData *extract_booklist(BookData *node_list, double rate, int cnt)
{
	int i;
	int entry_count = 1;
	BookData *extracted_list[36];

	extracted_list[0] = &node_list[0]; // best node

	double abs_threshold = 160000 * rate;

	for (i = 1; i < cnt; i++)
	{
		if (node_list[0].eval - node_list[i].eval <= abs_threshold)
		{
			extracted_list[i] = &node_list[i];
			entry_count++;
		}
	}

	return extracted_list[genrand_int32() % entry_count];
}
Exemplo n.º 28
0
byte IsTkIndivBetter(struct tkIndiv *refTkIndiv, struct tkIndiv *compTkIndiv)
{	
	static byte r = 0;
	if (refTkIndiv->fitness > compTkIndiv->fitness)
	{
		return 1; 
	}
	else if (refTkIndiv->fitness == compTkIndiv->fitness)
	{
        /*if (refTkIndiv->length > compTkIndiv->length)
        {
		    return 1;
        }
        else
        {*/
		  r = ((byte)(genrand_int32()) % 2);
	      return r;
			//return 0;
        //}
	}

	return 0;
}
Exemplo n.º 29
0
//一方の引数を指定した場合のテストケースを生成&ファイル出力
void fix_one(uint32_t a, FILE *fp) {
  uint32_t b;
  int i;
  b = ZERO;   fprintf(fp, "%08x %08x\n", a, b); fprintf(fp, "%08x %08x\n", b, a);
  b = NZERO;  fprintf(fp, "%08x %08x\n", a, b); fprintf(fp, "%08x %08x\n", b, a);
  b = INF;    fprintf(fp, "%08x %08x\n", a, b); fprintf(fp, "%08x %08x\n", b, a);
  b = NINF;   fprintf(fp, "%08x %08x\n", a, b); fprintf(fp, "%08x %08x\n", b, a);
  for (i = 0; i < 10; i++) {
    b = make_nan();
    fprintf(fp, "%08x %08x\n", a, b);
    fprintf(fp, "%08x %08x\n", b, a);
  }
  for (i = 0; i < 10; i++) {
    b = make_denormal();
    fprintf(fp, "%08x %08x\n", a, b);
    fprintf(fp, "%08x %08x\n", b, a);
  }
  for (i = 0; i < 500; i++) {
    b = genrand_int32();
    fprintf(fp, "%08x %08x\n", a, b);
    fprintf(fp, "%08x %08x\n", b, a);
  }
}
Exemplo n.º 30
0
int main(int argc, char* argv[])
{
    int p[4][2], i, im, id, status;
    unsigned long mseed, dseed;
    off_t nm, nd, msiz, dsiz;
    size_t nbuf, mbuf, dbuf;
    float *buf;
    double dp;
    pid_t pid[6]={1,1,1,1,1,1};
    sf_file mod=NULL;
    sf_file dat=NULL;
    sf_file pip=NULL;

    sf_init(argc,argv);

    mod = sf_input("mod");
    dat = sf_input("dat");

    if (SF_FLOAT != sf_gettype(mod) ||
	SF_FLOAT != sf_gettype(dat))
	sf_error("Need float type in mod and dat");

    nm = sf_filesize(mod);
    nd = sf_filesize(dat);

    nbuf = BUFSIZ/sizeof(float);
    buf = sf_floatalloc(nbuf);

    mseed = (unsigned long) time(NULL);
    init_genrand(mseed);
    mseed = genrand_int32();
    dseed = genrand_int32();

    for (i=0; i < argc-1; i++) {
	argv[i]=argv[i+1];
    }
    argv[argc-1] = sf_charalloc(6);
    snprintf(argv[argc-1],6,"adj=X");

    for (i=0; i < 4; i++) { /* make four pipes */
	if (pipe(p[i]) < 0) sf_error("pipe error:");
    }

    for (i=0; i < 6; i++) { /* fork six children */
	if ((pid[i] = fork()) < 0) sf_error("fork error:");
	if (0 == pid[i]) break;
    }

    if (0 == pid[0]) {	
	/* makes random model and writes it to p[0] */

	close(p[0][0]);
	close(STDOUT_FILENO);
	DUP(p[0][1]);

	pip = sf_output("out");
	sf_fileflush(pip,mod);

	init_genrand(mseed);
	for (msiz=nm, mbuf=nbuf; msiz > 0; msiz -= mbuf) {
	    if (msiz < mbuf) mbuf=msiz;

	    sf_random(mbuf,buf);

	    sf_floatwrite(buf,mbuf,pip);
	}
    } 

    if (0 == pid[1]) {
	/* reads from p[0], runs the program, and writes to p[1] */

	close(p[0][1]);
	close(STDIN_FILENO);
	DUP(p[0][0]);

	close(p[1][0]);
	close(STDOUT_FILENO);
	DUP(p[1][1]);

	argv[argc-1][4]='0';
	execvp(argv[0],argv);

	_exit(1);
    }

    if (0 == pid[2]) {
	/* reads from p[1] and multiplies it with random data */
	
	close(p[1][1]);
	close(STDIN_FILENO);
	DUP(p[1][0]);

	pip = sf_input("in");

	init_genrand(dseed);
	dp = 0.;
	for (dsiz=nd, dbuf=nbuf; dsiz > 0; dsiz -= dbuf) {
	    if (dsiz < dbuf) dbuf=dsiz;

	    sf_floatread(buf,dbuf,pip);
	    for (id=0; id < dbuf; id++) {
		dp += buf[id]*genrand_real1 ();
	    }	
	}
	sf_warning(" L[m]*d=%g",dp);

	_exit(2);
    }

    if (0 == pid[3]) {	
	/* makes random data and writes it to p[2] */

	close(p[2][0]);
	close(STDOUT_FILENO);
	DUP(p[2][1]);

	pip = sf_output("out");
	sf_fileflush(pip,dat);

	init_genrand(dseed);
	for (dsiz=nd, dbuf=nbuf; dsiz > 0; dsiz -= dbuf) {
	    if (dsiz < dbuf) dbuf=dsiz;

	    sf_random(dbuf,buf);

	    sf_floatwrite(buf,dbuf,pip);
	}
    } 

    if (0 == pid[4]) {
	/* reads from p[2], runs the adjoint, and writes to p[3] */

	close(p[2][1]);
	close(STDIN_FILENO);
	DUP(p[2][0]);

	close(p[3][0]);
	close(STDOUT_FILENO);
	DUP(p[3][1]);

	argv[argc-1][4]='1';
	execvp(argv[0],argv);

	_exit(4);
    }

    if (0 == pid[5]) {
	/* reads from p[3] and multiplies it with random model */
	
	close(p[3][1]);
	close(STDIN_FILENO);
	DUP(p[3][0]);

	pip = sf_input("in");

	init_genrand(mseed);
	dp = 0.;
	for (msiz=nm, mbuf=nbuf; msiz > 0; msiz -= mbuf) {
	    if (msiz < mbuf) mbuf=msiz;

	    sf_floatread(buf,mbuf,pip);


	    for (im=0; im < mbuf; im++) {
		dp += buf[im]*genrand_real1 ();
	    }	
	}
	sf_warning("L'[d]*m=%g",dp);
	
	_exit(5);
    }

    for (i=0; i < 6; i++) {
	if (0 == pid[i]) break;
    }

    if (6==i) {
	/* parent waits */
	waitpid(pid[2],&status,0);
	waitpid(pid[5],&status,0);
    
	exit(0);
    }
}