예제 #1
0
static void HomedGhost(GAME_STATE *ptr, G_GHOST *pGhost)
{
char c;

	switch(pGhost->iInHome)
		{
		case GIH_SHUFFLE:
				/* Move up into gateway?? */
				if (RND(2) == 0 && Pac_GetMap(ptr,pGhost->Pos.x,pGhost->Pos.y-1,&c) && c=='-')
					{
					pGhost->iInHome = GIH_GATEWAY;
					pGhost->Pos.y--;
					}
				else
					{
					c = RND(3);
					if (c == 0 && Pac_GetMap(ptr,pGhost->Pos.x-1,pGhost->Pos.y,&c) && c=='H')
						pGhost->Pos.x--;
					else if (c == 1 && Pac_GetMap(ptr,pGhost->Pos.x+1,pGhost->Pos.y,&c) && c=='H')
						pGhost->Pos.x++;
					}
				break;
		case GIH_GATEWAY:
				pGhost->Pos.y--; /* ASSUME: gate opens upwards */
				pGhost->iInHome = GIH_OUTSIDE;
				if (RND(2) == 0)
					pGhost->Direction = eDIR_Left;
				else
					pGhost->Direction = eDIR_Right;
				break;
		}
}
예제 #2
0
int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
#endif
{
   ulong32 a,b,c,d,t,u, *K;
   int r;
   
   LTC_ARGCHK(skey != NULL);
   LTC_ARGCHK(pt   != NULL);
   LTC_ARGCHK(ct   != NULL);
   LOAD32L(a,&pt[0]);LOAD32L(b,&pt[4]);LOAD32L(c,&pt[8]);LOAD32L(d,&pt[12]);

   b += skey->rc6.K[0];
   d += skey->rc6.K[1];

#define RND(a,b,c,d) \
       t = (b * (b + b + 1)); t = ROLc(t, 5); \
       u = (d * (d + d + 1)); u = ROLc(u, 5); \
       a = ROL(a^t,u) + K[0];                \
       c = ROL(c^u,t) + K[1]; K += 2;   
    
   K = skey->rc6.K + 2;
   for (r = 0; r < 20; r += 4) {
       RND(a,b,c,d);
       RND(b,c,d,a);
       RND(c,d,a,b);
       RND(d,a,b,c);
   }
   
#undef RND

   a += skey->rc6.K[42];
   c += skey->rc6.K[43];
   STORE32L(a,&ct[0]);STORE32L(b,&ct[4]);STORE32L(c,&ct[8]);STORE32L(d,&ct[12]);
   return CRYPT_OK;
}
예제 #3
0
void rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
#endif
{
   ulong32 a,b,c,d,t,u, *K;
   int r;

   LTC_ARGCHK(skey != NULL);
   LTC_ARGCHK(pt   != NULL);
   LTC_ARGCHK(ct   != NULL);
   
   LOAD32L(a,&ct[0]);LOAD32L(b,&ct[4]);LOAD32L(c,&ct[8]);LOAD32L(d,&ct[12]);
   a -= skey->rc6.K[42];
   c -= skey->rc6.K[43];
   
#define RND(a,b,c,d) \
       t = (b * (b + b + 1)); t = ROLc(t, 5); \
       u = (d * (d + d + 1)); u = ROLc(u, 5); \
       c = ROR(c - K[1], t) ^ u; \
       a = ROR(a - K[0], u) ^ t; K -= 2;
   
   K = skey->rc6.K + 40;
   
   for (r = 0; r < 20; r += 4) {
       RND(d,a,b,c);
       RND(c,d,a,b);
       RND(b,c,d,a);
       RND(a,b,c,d);
   }
   
#undef RND

   b -= skey->rc6.K[0];
   d -= skey->rc6.K[1];
   STORE32L(a,&pt[0]);STORE32L(b,&pt[4]);STORE32L(c,&pt[8]);STORE32L(d,&pt[12]);
}
예제 #4
0
static void MoveGhost(GAME_STATE *ptr, G_GHOST *pGhost)
{
int tries=0;

	if (!IsNextMoveValid(ptr, pGhost))
		{ /* must be either 1 or 2 valid directions */
		tDir w1,w2;

		switch(pGhost->Direction) 
			{
			case eDIR_Right:
			case eDIR_Left:	w1=eDIR_Up, w2=eDIR_Down; break;
			case eDIR_Up:
			case eDIR_Down:	w1=eDIR_Left, w2=eDIR_Right; break;
			}
		if (RND(2)==0)	/* try w1 first, then w2 */
			{
			pGhost->Direction = w1;
			if (!IsNextMoveValid(ptr, pGhost))
				pGhost->Direction = w2;
			}
		else
			{
			pGhost->Direction = w2;
			if (!IsNextMoveValid(ptr, pGhost))
				pGhost->Direction = w1;
			}
		}

	if (RND(34) == 0 && pGhost->Pos.x != ptr->Player.Pos.x && pGhost->Pos.y != ptr->Player.Pos.y)
		{
		pGhost->Direction = RND(4);	/* a little bit bad! */
		while(++tries < 4)
			{
			if (IsNextMoveValid(ptr, pGhost))
				break;/* found a new dir */
			else
				if (++pGhost->Direction == 4)
					pGhost->Direction = 0;
			}
		}

	/* Move the ghost */
	switch(pGhost->Direction)
		{
		case eDIR_Left:		pGhost->Pos.x--; break;
		case eDIR_Right:	pGhost->Pos.x++; break;
		case eDIR_Up:		pGhost->Pos.y--; break;
		case eDIR_Down:		pGhost->Pos.y++; break;
		}
	/* Check for tunnel */
	if (pGhost->Pos.x < 0)	pGhost->Pos.x = ptr->iMapWidth-1;
	if (pGhost->Pos.x >= ptr->iMapWidth) pGhost->Pos.x = 0;
}
예제 #5
0
void calc_entropy (
  MODEL *model,			/* the model */
  DATASET *dataset  		/* the dataset */
)
{
  int i, j;
  double *rentropy = model->rentropy;		/* IC of each column */
  double ent = 0;				/* entropy per column */
  double rel = 0;				/* relative entropy per col. */
  int alength = dataset->alength;		/* length of alphabet */
  double *back = dataset->back;			/* background model freqs */
  THETA obs = model->obs;			/* observed frequencies */
  int w = model->w;				/* width of motif */
  int N = model->nsites_dis;			/* number of sites */
  double log_pop;				/* log product of col p-value */
  double max_ic = LOG(alength)/LOG(2);		// maximum IC per column
  //double e = (alength-1) / (2 * LOG(2) * N);	// small sample correction
  double ic = 0;				// "corrected" IC

  /* calculate the relative entropy of each column in motif */
  model->llr = log_pop = 0;
  for (i=0; i<w; i++) {			/* position */
    double llr;				/* log likelihood ratio of column */
    rentropy[i] = 0.0; 
    double H = 0;			// negative entropy in this column
    for (j=0; j<alength; j++) {		/* alphabet letter */
      double f = obs(i, j);		/* motif freq */
      double p = back[j];		/* background freq */
      double h = f ? f * LOG2(f) : 0;	// entropy of current letter
      rel += p ? f * LOG2(p) : 0;	/* total relative entropy */
      ent += h;				/* total entropy */
      H += -h;				// negative entropy in this column
      rentropy[i] += (f && p) ? f * LOG(f/p) : 0;
    } /* alphabet letter */
    llr = N * rentropy[i];		/* log likelihood ratio */
    RND(llr, RNDDIG, llr);		/* round to RNDDIG places */
    model->llr += llr;                  /* llr for model */
    log_pop += get_llr_pv(llr, N, 1, LLR_RANGE, 1.0, alength, back);
    rentropy[i] /= LOG(2);
    // ic += MAX(0, (max_ic - (H + e)));
    ic += max_ic - H;
  } /* position in motif */

  /* compute the log E-value of the motif */
  model->logev = get_log_sig(-log_pop, model->mtype, w, N, N, model->invcomp,
    model->pal, dataset);

  model->rel = (ent - rel)/w;		/* compute rel. entropy/col */

  // LOGO total information content
  RND(ic, RNDDIG, ic);			// round to RNDDIG places
  model->ic = ic;

} /* calc_entropy */
예제 #6
0
/* This a helper function that generates a random password with a
   number of characters from a set of character classes.

   If there are n classes, and the size of each class is Pi, and the
   number of characters from each class is Ni, the number of possible
   passwords are (given that the character classes are disjoint):

     n             n
   -----        /  ----  \
   |   |  Ni    |  \     |
   |   | Pi     |   \  Ni| !
   |   | ---- * |   /    |
   |   | Ni!    |  /___  |
    i=1          \  i=1  /

    Since it uses the RND function above, neither the size of each
    class, nor the total length of the generated password should be
    larger than 127 (without fixing RND).

   */
static void
generate_password(char **pw, int num_classes, ...)
{
    struct {
        const char *str;
        int len;
        int freq;
    } *classes;
    va_list ap;
    int len, i;
    unsigned char rbuf[8]; /* random buffer */
    int rleft = 0;

    *pw = NULL;

    classes = malloc(num_classes * sizeof(*classes));
    if(classes == NULL)
        return;
    va_start(ap, num_classes);
    len = 0;
    for(i = 0; i < num_classes; i++) {
        classes[i].str = va_arg(ap, const char*);
        classes[i].len = strlen(classes[i].str);
        classes[i].freq = va_arg(ap, int);
        len += classes[i].freq;
    }
    va_end(ap);
    *pw = malloc(len + 1);
    if(*pw == NULL) {
        free(classes);
        return;
    }
    for(i = 0; i < len; i++) {
        int j;
        int x = RND(rbuf, sizeof(rbuf), &rleft) % (len - i);
        int t = 0;
        for(j = 0; j < num_classes; j++) {
            if(x < t + classes[j].freq) {
                (*pw)[i] = classes[j].str[RND(rbuf, sizeof(rbuf), &rleft)
                                          % classes[j].len];
                classes[j].freq--;
                break;
            }
            t += classes[j].freq;
        }
    }
    (*pw)[len] = '\0';
    memset(rbuf, 0, sizeof(rbuf));
    free(classes);
}
예제 #7
0
static void Transform(Sha256* sha256)
{
    word32 S[8], W[64], t0, t1;
    int i;

    /* Copy context->state[] to working vars */
    for (i = 0; i < 8; i++)
        S[i] = sha256->digest[i];

    for (i = 0; i < 16; i++)
        W[i] = sha256->buffer[i];

    for (i = 16; i < 64; i++)
        W[i] = Gamma1(W[i-2]) + W[i-7] + Gamma0(W[i-15]) + W[i-16];

    for (i = 0; i < 64; i += 8) {
        RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],i+0);
        RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],i+1);
        RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],i+2);
        RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],i+3);
        RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],i+4);
        RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],i+5);
        RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],i+6);
        RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],i+7);
    }

    /* Add the working vars back into digest state[] */
    for (i = 0; i < 8; i++) {
        sha256->digest[i] += S[i];
    }
}
예제 #8
0
파일: sha512.c 프로젝트: sdhczw/winnermicro
void  sha512_compress(psDigestContext_t * md, unsigned char *buf)
#endif
{
	uint64 S[8], W[80], t0, t1;
    int i;

    /* copy state into S */
    for (i = 0; i < 8; i++) {
        S[i] = md->sha512.state[i];
    }

    /* copy the state into 1024-bits into W[0..15] */
    for (i = 0; i < 16; i++) {
		LOAD64H(W[i], buf + (8*i));
    }

    /* fill W[16..79] */
    for (i = 16; i < 80; i++) {
        W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
    }        

    /* Compress */
#ifndef PS_SHA512_IMPROVE_PERF_INCREASE_CODESIZE
    for (i = 0; i < 80; i++) {
        t0 = S[7] + Sigma1(S[4]) + Ch(S[4], S[5], S[6]) + K[i] + W[i];
		t1 = Sigma0(S[0]) + Maj(S[0], S[1], S[2]);
        S[7] = S[6];
        S[6] = S[5];
        S[5] = S[4];
        S[4] = S[3] + t0;
        S[3] = S[2];
        S[2] = S[1];
        S[1] = S[0];
        S[0] = t0 + t1;
    }
#else
#define RND(a,b,c,d,e,f,g,h,i)                    \
     t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i];   \
     t1 = Sigma0(a) + Maj(a, b, c);                  \
     d += t0;                                        \
     h  = t0 + t1;

     for (i = 0; i < 80; i += 8) {
         RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],i+0);
         RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],i+1);
         RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],i+2);
         RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],i+3);
         RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],i+4);
         RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],i+5);
         RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],i+6);
         RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],i+7);
     }
#endif /* PS_SHA512_IMPROVE_PERF_INCREASE_CODESIZE */

	/* feedback */
	for (i = 0; i < 8; i++) {
        md->sha512.state[i] = md->sha512.state[i] + S[i];
    }
}
예제 #9
0
int tryInsert()
{
  double testx, testy;
  testx=RND()*L;
  testy=RND()*L;
  if (Pinsert(testx, testy))
  {
    X[n]=testx;
    Y[n]=testy;
    printf("%d:  inserted at %lf, %lf\n",n, testx,testy);
    n++;
    return 1;
  }
  else return 0;
}
예제 #10
0
static Header *compact(MemBlk *mb) 
{ 
	char *end = (char *) (mb+1) + mb->size; 
	Header *h = (Header *) (mb+1); 
	Header *to, *pto=NULL; 

	for (to=h ; (char *) h < end ; h = NEXTH(h)) { 
		if (h->status == 'F') 
			continue; 
		if (to != h) { 
			memcpy(to, h, h->rsize+sizeof(Header)); 
			if (h->next) 
				*((Header **) to->next) = to + 1; 
		} 
		to->size = RND(to->rsize); 
		pto = to; 
		to = NEXTH(to); 
	} 
	if ((char *) to >= end) 
		return NULL; 
	to->status = 'F'; 
	to->size = (end - (char *) to) - sizeof(Header); 
	if (!to->size) { 
		if (pto) 
			pto->size += to->size + sizeof(Header); 
		return NULL; 
	} 
	return to; 
} 
예제 #11
0
int main(){	
	struct cache_manager *lru_manager;
	int i;

	lru_init(&lru_manager,"LRU", 500, 500, 1, 0);

	for(i =0;i < 1000000;i++){
		struct lru_node *ln = NULL;
		unsigned int blkno = RND(10000);

		ln = CACHE_SEARCH(lru_manager, blkno);
		if(!ln){
			
			ln = CACHE_REPLACE(lru_manager, 0, FCL_REPLACE_ANY);
			ln = CACHE_ALLOC(lru_manager, ln, blkno);
			CACHE_INSERT(lru_manager, ln);
		}else{
			ln = CACHE_REMOVE(lru_manager, ln);
			CACHE_INSERT(lru_manager, ln);
		}
	}	

	CACHE_PRINT(lru_manager, stdout);
	CACHE_CLOSE(lru_manager);

	return 0;
}
예제 #12
0
/* compress 512-bits */
static int sha256_compress(struct sha256_state *md,
                           unsigned char *buf)
{
  unsigned long S[8], W[64], t0, t1;
  unsigned long t;
  int i;
  /* copy state into S */
  for(i = 0; i < 8; i++) {
    S[i] = md->state[i];
  }
  /* copy the state into 512-bits into W[0..15] */
  for(i = 0; i < 16; i++)
    W[i] = WPA_GET_BE32(buf + (4 * i));
  /* fill W[16..63] */
  for(i = 16; i < 64; i++) {
    W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) +
      W[i - 16];
  }
  /* Compress */
#define RND(a,b,c,d,e,f,g,h,i)                    \
  t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i]; \
  t1 = Sigma0(a) + Maj(a, b, c);                  \
  d += t0;                                        \
  h = t0 + t1;
  for(i = 0; i < 64; ++i) {
    RND(S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7], i);
    t = S[7]; S[7] = S[6]; S[6] = S[5]; S[5] = S[4];
    S[4] = S[3]; S[3] = S[2]; S[2] = S[1]; S[1] = S[0]; S[0] = t;
  }
  /* feedback */
  for(i = 0; i < 8; i++) {
    md->state[i] = md->state[i] + S[i];
  }
  return 0;
}
예제 #13
0
static void more_core(unsigned n) 
{ 
	unsigned sz; 
	unsigned as; 
	MemBlk *mb; 
	Header *h; 

	sz = n > DBS ? n : DBS; 
	sz = RND(sz); 
	as = sizeof(MemBlk) + sizeof(Header) + sz; 
	mb = (MemBlk *) malloc(as); 
	if (!mb) { 
#ifndef __COSMIC__ 
		fprintf(stderr, "\nOut of memory.\n"); 
#endif 


#line 235 "memalloc.d"
		exit(1); 
	} 
	mb->next = MMBP; 
	MMBP = mb; 
	mb->size = sz + sizeof(Header); 

	h = (Header *) (mb+1); 
	h->status = 'U'; 
	h->next = NULL; 
	h->size = sz; 
	MA_free(h+1); 
} 
예제 #14
0
static void DormantGhost(GAME_STATE *ptr, G_GHOST *pGhost)
{
	/* Wake him up?? */
	if (RND(30) < 2)
		Pac_ActivateGhost(pGhost, 12,10,eDIR_Left);
	
}
예제 #15
0
int d(int n, int x)
{
    int tmp = n;

    while (n--)
	tmp += RND(x);
    return tmp;
}
예제 #16
0
파일: testxg.c 프로젝트: Kinglions/modizer
void putdata(int nini, int nend, double *a)
{
    int j, seed = 0;

    for (j = nini; j <= nend; j++) {
        a[j] = RND(&seed);
    }
}
예제 #17
0
/* neglectible % of execution time */
static void
animateLMorph(struct state *st)
{
    int i;
    if (st->currGamma > st->maxGamma) {
        st->currGamma = 0.0;
        st->nFrom = st->nTo;
        st->nTo = st->nNext;
        st->aFrom = st->a[st->nFrom];
	st->aTo = st->a[st->nTo];
        do {
            st->nNext = RND(st->numFigs);
        } while (st->nNext == st->nTo);
	st->aNext = st->a[st->nNext];

	st->shift = RND(st->numPoints);
        if (RND(2)) {
            /* reverse the array to get more variation. */
            int    i1, i2;
            XPoint p;
            
            for (i1 = 0, i2 = st->numPoints - 1; i1 < st->numPoints / 2; i1++, i2--) {
                p = st->aNext[i1];
                st->aNext[i1] = st->aNext[i2];
                st->aNext[i2] = p;
            }
        }

	/* calculate the slopes */
	for (i = 0; i < st->numPoints ; i++) {
            st->aSlopeFrom[i].x = st->aSlopeTo[i].x;
            st->aSlopeFrom[i].y = st->aSlopeTo[i].y;
            st->aSlopeTo[i].x = st->aNext[i].x - st->aTo[i].x;
            st->aSlopeTo[i].y = (st->aNext[i].y - st->aTo[i].y);
	}
    }

    createPoints(st);
    drawImage(st);
    st->aPrev = st->aCurr;
    st->aCurr = st->aWork[st->nWork ^= 1];

    st->currGamma += st->deltaGamma;
}
예제 #18
0
void putdata2d(int n1, int n2, double **a)
{
    int j1, j2, seed = 0;

    for (j1 = 0; j1 <= n1 - 1; j1++) {
        for (j2 = 0; j2 <= n2 - 1; j2++) {
            a[j1][j2] = RND(&seed);
        }
    }
}
예제 #19
0
void mapCavern::Randomise()
{
	int limit = (m_width * m_height * 2) / 5;
	int count = 0;
	while (count < limit)
	{
		int i, j;

		i = RND(m_width);
		j = RND(m_height);
		if (WallAt(i, j) == WALL_Any)
		{
			WallAt(i, j) = WALL_None;
			count++;
		}
	}

#if 0
	for ( int i = 0; i < m_width * m_height; i++ )
	{
		int random = rand() % 4;
		hnFloor type = WALL_Any;

		switch( random )
		{
			case 0:
			type = WALL_Any;
			break;
			case 1:
			type = WALL_None;
			break;
			case 2:
			type = MATERIAL_Ice;
			break;
			case 3:
			type = MATERIAL_Lava;
			break;
		}

		m_tile[i] = type;
	}
#endif //0
}
예제 #20
0
파일: testxg.c 프로젝트: Kinglions/modizer
double errorcheck(int nini, int nend, double scale, double *a)
{
    int j, seed = 0;
    double err = 0, e;

    for (j = nini; j <= nend; j++) {
        e = RND(&seed) - a[j] * scale;
        err = MAX(err, fabs(e));
    }
    return err;
}
예제 #21
0
void Pac_InitialiseGhosts(GAME_STATE *ptr)
{
int i;
int xBase = 12;
	
	for(i=0;i<MAX_GHOSTS;i++) {
		ptr->Ghosts[i].bActive = 0;
		if (RND(2)) {
			Pac_ActivateGhost(&ptr->Ghosts[i], xBase + 2*i, 10, eDIR_Left);
		}
	}
}
예제 #22
0
파일: anemone.c 프로젝트: Zygo/xscreensaver
static void
createPoints(struct state *st)
{
  int i;
  int withdrawall = RND(st->withdraw);

  for (i = 0; i< st->arms; i++) {
    st->aCurr = st->appD + i;
    if (!withdrawall) {
      st->aCurr->growth = -st->finpoints;
      st->turndelta = -st->turndelta;
    }

    else if (withdrawall<11) st->aCurr->growth = -st->aCurr->numpt;

    else if (RND(100)<st->aCurr->rate) {
      if (st->aCurr->growth>0) {
	if (!(--st->aCurr->growth)) st->aCurr->growth = -RND(st->finpoints) - 1;
	st->vCurr = st->vPendage + (st->finpoints + 1) * i + st->aCurr->numpt - 1;
	if (st->aCurr->numpt<st->finpoints - 1) {
	  /* add a piece */	
	  st->vNext = st->vCurr + 1;
	  st->aCurr->numpt++;
	  st->vNext->sx = st->vCurr->sx + RND(3) - 1;
	  st->vNext->sy = st->vCurr->sy + RND(3) - 1;
	  st->vNext->sz = st->vCurr->sz + RND(3) - 1;
	  st->vCurr = st->vNext + 1;
	  st->vCurr->x = st->vNext->x + st->vNext->sx;
	  st->vCurr->y = st->vNext->y + st->vNext->sy;
	  st->vCurr->z = st->vNext->z + st->vNext->sz;
	}
      }
    }
  }
}
예제 #23
0
파일: anemone.c 프로젝트: Zygo/xscreensaver
static void
drawImage(struct state *st, Drawable curr_window, double sint, double cost)
{
  int q,numpt,mx2 = st->mx / 2;
  double cx,cy,cz,nx = 0,ny = 0,nz = 0;

  if ((numpt = st->aCurr->numpt)==1) return;
  XSetForeground(st->dpy, st->gcDraw, st->aCurr->col);
    
  st->vNext = st->vCurr + 1;

  cx = st->vCurr->x;
  cy = st->vCurr->y;
  cz = st->vCurr->z;


  for (q = 0; q < numpt - 1; q++) {
    nx = st->vNext->x + 2 - RND(5);
    ny = st->vNext->y + 2 - RND(5);
    nz = st->vNext->z + 2 - RND(5);

    XDrawLine(st->dpy, curr_window, st->gcDraw,
              mx2 + cx * cost - cz * sint, cy,
              mx2 + nx * cost - nz * sint, ny);
    st->vCurr++;
    st->vNext++;

    cx = nx;
    cy = ny;
    cz = nz;
  }
  XSetLineAttributes(st->dpy, st->gcDraw, st->width * 3,
                     LineSolid, CapRound, JoinBevel);
  XDrawLine(st->dpy, curr_window, st->gcDraw,
            st->mx / 2 + cx * cost - cz * sint, cy,
            st->mx / 2 + nx * cost - nz * sint, ny);
  XSetLineAttributes(st->dpy, st->gcDraw, st->width,
                     LineSolid, CapRound, JoinBevel);

}
예제 #24
0
void PIDThread::run()
{
    while(1)
    {
        usleep(10000); // 10 ms
        error_last_time = error_this_time;
        error_this_time = targetPosition - currentPosition;
        error_integral += error_this_time;
        double speed = calculateSpeed();
        if (checkEnd(speed)) this->terminate();
        emit updatePosition(RND((currentPosition + speed) * 10));
    }
}
예제 #25
0
/* compress 1024-bits */
static int sha512_compress(sha512_context *md, unsigned char *buf)
{
    u64 S[8], W[80], t0, t1;
    int i;

    /* copy state into S */
    for (i = 0; i < 8; i++) {
        S[i] = md->state[i];
    }

    /* copy the state into 1024-bits into W[0..15] */
    for (i = 0; i < 16; i++) {
        LOAD64H(W[i], buf + (8*i));
    }

    /* fill W[16..79] */
    for (i = 16; i < 80; i++) {
        W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
    }        

/* Compress */
    #define RND(a,b,c,d,e,f,g,h,i) \
    t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i]; \
    t1 = Sigma0(a) + Maj(a, b, c);\
    d += t0; \
    h  = t0 + t1;

    for (i = 0; i < 80; i += 8) {
       RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],i+0);
       RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],i+1);
       RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],i+2);
       RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],i+3);
       RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],i+4);
       RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],i+5);
       RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],i+6);
       RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],i+7);
   }

   #undef RND



    /* feedback */
   for (i = 0; i < 8; i++) {
        md->state[i] = md->state[i] + S[i];
    }

    return 0;
}
예제 #26
0
double errorcheck2d(int n1, int n2, double scale, double **a)
{
    int j1, j2, seed = 0;
    double err = 0, e;

    for (j1 = 0; j1 <= n1 - 1; j1++) {
        for (j2 = 0; j2 <= n2 - 1; j2++) {
            e = RND(&seed) - a[j1][j2] * scale;
            err = MAX(err, fabs(e));
        }
    }
    return err;
}
예제 #27
0
파일: rnd.c 프로젝트: thejoshwolfe/nethack
/* good luck approaches 0, bad luck approaches (x-1) */
int rnl(int x) {
  int i;

  i = RND(x);

  if (Luck && rn2(50 - Luck)) {
    i -= (x <= 15 && Luck >= -5 ? Luck/3 : Luck);
    if (i < 0) i = 0;
    else if (i >= x) i = x-1;
  }

  return i;
}
예제 #28
0
파일: hhea.c 프로젝트: Acidburn0zzz/afdko
int hheaFill(hotCtx g)
	{
	hheaCtx h = g->ctx.hhea;

	h->tbl.version 					= VERSION(1, 0);
	
	{
		if  (OVERRIDE(g->font.hheaAscender))
			h->tbl.ascender = g->font.hheaAscender;
		else
			h->tbl.ascender = g->font.TypoAscender;
		
		if  (OVERRIDE(g->font.hheaDescender))
			h->tbl.descender = g->font.hheaDescender;
		else
			h->tbl.descender = g->font.TypoDescender;
		
		if  (OVERRIDE(g->font.hheaLineGap))
			h->tbl.lineGap = g->font.hheaLineGap;
		else
			h->tbl.lineGap = g->font.TypoLineGap;
	}
		
	h->tbl.advanceWidthMax 			= g->font.maxAdv.h;
	h->tbl.minLeftSideBearing 		= g->font.minBearing.left;
	h->tbl.minRightSideBearing 		= g->font.minBearing.right;
	h->tbl.xMaxExtent 				= g->font.maxExtent.h;

	if (g->font.ItalicAngle == 0)
		{
		h->tbl.caretSlopeRise 		= 1;
		h->tbl.caretSlopeRun 		= 0;
		}
	else
		{
		h->tbl.caretSlopeRise 		= 1000;
		h->tbl.caretSlopeRun 		=
			(short)RND(tan(FIX2DBL(-g->font.ItalicAngle) / RAD_DEG) * 1000);
		}
	if (h->tbl.caretOffset == SHRT_MAX)
		h->tbl.caretOffset = (g->font.ItalicAngle == 0)? 0: calcCaretOffset(g);

	h->tbl.reserved[0] 				= 0;
	h->tbl.reserved[1] 				= 0;
	h->tbl.reserved[2] 				= 0;
	h->tbl.reserved[3] 				= 0;
	h->tbl.metricDataFormat 		= 0;
	h->tbl.numberOfLongHorMetrics 	= hmtxGetNLongHorMetrics(g);

	return 1;
	}
예제 #29
0
파일: TREE.CPP 프로젝트: newmen/seasons
void Tree::Divis(const Point* begin, const Point* end, const int& color)
{
    double* dl = new double(begin->Range(end));
    if(*dl < kleafrate*size/33.3)
    {
        delete dl;
        return;
    }

    Point middle;

    double* rnd = new double(RND());

    if(begin->GetX() == end->GetX() || begin->GetY() == end->GetY())
    {
        int krnd = (*rnd <= 0.5) ? 1 : -1;

        if(begin->GetX() == end->GetX())
            middle.SetXY(begin->GetX() + ((begin->GetX() + krnd * *dl/2 > 0.0) ?
                                          krnd : -krnd) * *dl/2, min(begin->GetY(), end->GetY()) + *dl/2);

        if(begin->GetY() == end->GetY())
            middle.SetXY(min(begin->GetX(), end->GetX()) + *dl/2,
                         begin->GetY() + ((begin->GetY() + krnd * *dl/2 > 0.0) ?
                                          krnd : -krnd) * *dl/2);
    }
    else if(*rnd <= 0.5) middle.SetXY(begin->GetX(), end->GetY());
    else middle.SetXY(end->GetX(), begin->GetY());

    delete dl;

    double *chance = new double(center.Range(&sun)/middle.Range(&sun));

    if(sflowers != 0 && *rnd < 0.025 * *chance)
    {
        f = middle;
        f.Draw(color);
    }
    else
    {
        l = middle;
        if(*rnd < Fi / *chance / 0.8) l.Draw(color3);
        else l.Draw(color4);
    }

    delete chance;
    delete rnd;

    Divis(begin, &middle, color);
    Divis(&middle, end, color);
}
예제 #30
0
파일: anemone.c 프로젝트: Zygo/xscreensaver
static void
animateAnemone(struct state *st, Drawable curr_window)
{
  int i;
  double sint = sin(st->turn),cost = cos(st->turn);

  st->aCurr = st->appD;
  for (i = 0; i< st->arms; i++) {
    st->vCurr = st->vPendage + (st->finpoints + 1) * i;
    if (RND(25)<st->aCurr->rate) {
      if (st->aCurr->growth<0) {
	st->aCurr->numpt -= st->aCurr->numpt>1;
	if (!(++st->aCurr->growth)) st->aCurr->growth = RND(st->finpoints - st->aCurr->numpt) + 1;
      }
    }
    drawImage(st, curr_window, sint, cost);
    st->turn += st->turndelta;
    st->aCurr++;
  }
  createPoints(st);

  if (st->turn >= TWO_PI) st->turn -= TWO_PI;
}