Ejemplo n.º 1
0
/*
 * read number for mother, according to different chr
 *@return:a read number
 */
int getAforMom(sParameter *parameter, int chrNum,range *prange)
{
	int a;
	//如果为母体样本
	//printf("parentflag=%c\n",parameter->parentFlag);
	if(parameter->parentFlag == 'M'){
		//printf("M:get mother window length here\n");
	    if(chrNum <24)
		      a = prange->a_mom;
		if(chrNum == 24)
		      a = new_rand()%3;
	}
	//printf("mother a =%d\n",a);
	return a;
}
Ejemplo n.º 2
0
/*
 *return a number between x-y and x+y
 */
int randValue(int x, int y)
{
	if(y==0){
		return x;
	}else{
		int flex=0;
		x-=y;
		y+=y;
		flex = new_rand()%(y);
		//printf("flex=%d \n",flex);
		x+=flex;
		//printf("in randValue():%d\n",x);
		return x;
	}
}
Ejemplo n.º 3
0
int main() {

int hist[4]={0};
int test_num;
int counter=0;
int new_rand() {
if(counter>30) {counter=0;}
if(counter==0) {int test_num=rand();}


int lsb=counter;
int msb=lsb+0;

int result=(test_num>>lsb) &~(~0<<(msb-lsb+1));
counter++;
return result;

}

int i;

for(i=0; i<10000000;i++){
int r=new_rand();

hist[r]++;

}

for(i=0; i<4;i++){

printf("\nhist[%i]: %i", i, hist[i]);

}


printf("\n");


}
Ejemplo n.º 4
0
int main(int argc, char *argv[]) {
//sgenrand(time(NULL));
int k, curr_pos, check;
int chunk; /* Repeat experiment in chunks. */
srand(SEED);

printf("# Info: $Header: /home/ma/p/pruess/.cvsroot/manna_range/dmitry_20151021/manna_stack_clean_edited.c,v 1.2 2015/10/21 11:37:00 pruess Exp $\n");
preamble(argc, argv);

PRINT_PARAM(SEED, "%lu");
PRINT_PARAM(LENGTH, "%lu");
PRINT_PARAM(DROP_LOCATION, "%lu");
PRINT_PARAM(total_malloced, "%lli");


printf("# Info: Expected avalanche size: <s>(x) = 1+(1/2) (<s>(x+1)+<s>(x-1)), BC <s>(0)=0, <s>(L+1)=0, solved by <s>(x)=(L+1-x)x/2.\n");
printf("# Info: Here L=LENGTH=%lu and x=DROP_LOCATION+1=%lu, so expect %g\n", LENGTH, DROP_LOCATION+1, ((double)(DROP_LOCATION+1))*((double)(LENGTH-DROP_LOCATION))/2.);


for (chunk=1; ((chunk<=NUM_CHUNKS) || (NUM_CHUNKS<0)); chunk++) {
MOMENTS_INIT(size);
for (drop = 0; drop < N_ROLLS; drop++) {  // big droppping cycle

size=0;

#if (1-MODE_BSF)

#define PUSH(a) stack[stack_used++]=(a)
#define POP(a)  (a)=stack[--stack_used]

if(lattice[DROP_LOCATION] == 0) {
      lattice[DROP_LOCATION] = 1;
      }
 else {
      PUSH(DROP_LOCATION); 
      PUSH(DROP_LOCATION);
      lattice[DROP_LOCATION] = 0;
      size++;
 }

/* If validated, optimse by turning stack operations into macros, 
 * optime random number drawing (rather than having doubles in the tree
 * have integers there and draw an integer to compare against),
 * optimise the shuffling of particles. 
 *
 * I have added MOMENT macros for size. */

  while(stack_used != 0) {
    POP(curr_pos);
/* This code with the "check" looks clumsy. I suppose
 * you are "following through" topplings? I would think
 * there is no point doing this later. Anyway, we validate
 * this code and take it from there. */
    do {
      curr_pos = curr_pos+ ( (rand()>RAND_MAX/2) ? 1 : -1); //move_ball(curr_pos);
 
      if((curr_pos>=0) && (curr_pos<LENGTH)) {
        if(lattice[curr_pos] == 0)  {
          lattice[curr_pos] = 1;
          }
        else  {
          size++;
          lattice[curr_pos] = 0;
          PUSH(curr_pos);
        }
    } 
    else {break;}
  }while( (lattice[curr_pos] != 1));
}/* end of while(stack_used != 0) look */
#endif

#if (MODE_BSF)
{
int npos;

#define PUSH(a) stack[stack_used++]=(a)
#define POP(a)  (a)=stack[--stack_used]

if (lattice[DROP_LOCATION]++==1) {
  PUSH(DROP_LOCATION);
  //size++;
    while(stack_used) {
      size++;
      POP(curr_pos);
      do {

	lattice[curr_pos]-=2;
	npos=curr_pos+ ( (new_rand()!=(int)0) ? 1 : -1);
	if ((npos>=0) && (npos<LENGTH)) {
	  if (lattice[npos]++==1) {PUSH(npos);}
	}
//rand()>RAND_MAX/2
//new_rand()==0
        npos=curr_pos+ ( (new_rand()!=(int)0) ? 1 : -1);
	if ((npos>=0) && (npos<LENGTH)) {
	  if (lattice[npos]++==1) {PUSH(npos);}
	}


        
      } while (lattice[curr_pos]>1);
    }
  }
}
#endif

//printf("size is %i\n", size);
MOMENTS(size,size);
} /* end of iterations loop */
MOMENTS_OUT(size);

} /* chunk */
postamble();
}