Beispiel #1
0
Quest QuestionShow::getQuest(int level)
{
    Q_ASSERT(level < 6 && level > 0);
    int randNum = getRand(questLists[level -1].length());
    Q_ASSERT(questLists[level-1].length() > randNum); //random ma dać mniejszą liczbę niż rozmiar listy
    return questLists[level-1].takeAt(randNum); //kasuje zwracany Quest z listy
}
Beispiel #2
0
// genNewTile()
// Description: generate new tile in random slot
void Game::genNewTile(){
    int nSlot = m_grid.getSlotNo();
    int randSlot = getRand() % nSlot;
    bool success = m_grid.setSlot(randSlot, getNextTile());
    assert(success);
    setNextTile();
}
static inline float
mmRand (int   min,
	int   max,
	float divisor)
{
	return ((float) getRand(min, max)) / divisor;
Beispiel #4
0
void *my_thread_process (void * arg)
{
	int i;
	CLIENT *clnt = NULL;
	struct datas vars;
	static double result = 0;
    struct timeval total_timeout;

    total_timeout.tv_sec = 1;
	total_timeout.tv_usec = 1;

	clnt = clnt_create(hostname, progNum, VERSNUM, nettype);

	if (clnt == NULL)
	{
		printf("5\n");
		pthread_exit (5);
	}

	if (run_mode == 1)
	{
		fprintf(stderr, "Thread %d\n", atoi(arg));
	}

	vars.a = getRand();
	vars.b = getRand();
	vars.c = getRand();

	resTbl[atoi(arg)].locRes = vars.a + (vars.b * vars.c);

    clnt_call((CLIENT *)clnt, CALCTHREADPROC,
				(xdrproc_t)xdr_datas, (char *)&vars, // xdr_in
                (xdrproc_t)xdr_double, (char *)&resTbl[atoi(arg)].svcRes, // xdr_out
				total_timeout);

	thread_array_result[atoi(arg)] = (resTbl[atoi(arg)].svcRes == resTbl[atoi(arg)].locRes) ? 0 : 1;

	if (run_mode == 1)
	{
		fprintf(stderr, "Thread #%d calc : %lf, received : %lf\n",
		        atoi(arg), resTbl[atoi(arg)].locRes,
		        resTbl[atoi(arg)].svcRes);
	}

    pthread_exit (0);
}
Beispiel #5
0
int getBurst(int n, int verbose)
{
	int rand = getRand();
	if(verbose == 2){
		printf("Find burst when choosing ready process to run %i\n", rand);
	}
	return (1 + rand%n);
}
void RippleAddress::setSeedRandom()
{
	// XXX Maybe we should call MakeNewKey
	uint128 key;

	getRand(key.begin(), key.size());

	RippleAddress::setSeed(key);
}
Beispiel #7
0
/*
 * This function arms the timer with a uniform range, as requested by page 105 of the standard (for sending delayReqs.)
 * actual time will be U(0, interval * 2.0);
 *
 * PTPv1 algorithm was:
 *    ptpClock->R = getRand(&ptpClock->random_seed) % (PTP_DELAY_REQ_INTERVAL - 2) + 2;
 *    R is the number of Syncs to be received, before sending a new request
 * 
 */ 
void timerStart_random(UInteger16 index, float interval, IntervalTimer * itimer)
{
	float new_value;

	new_value = getRand() * interval * 2.0;
	DBG2(" timerStart_random: requested %.2f, got %.2f\n", interval, new_value);
	
	timerStart(index, new_value, itimer);
}
Beispiel #8
0
// Randomly choose a float text format
static const TCHAR* getFloatFormat()
{
	switch (int(getRand(0.0, 3.0))) {
	case 0:
		return _T("%.10f");
	case 1:
		return _T("%.10g");
	}
	return _T("%.10e");
}
Beispiel #9
0
// Randomly choose an integer text format.
static const TCHAR* getIntFormat(int& v)
{
	switch (int(getRand(0.0, 3.0))) {
	case 0:
		return _T("%d");
	case 1:
		return _T("0x%x");
	}
	v = -v;
	return _T("-0x%x");
}
OrderType Customer::chooseDrink()
{
	//random number between 0 and 99
	int num = getRand() % 100;
	if (num < RATIO_BEER * 100)
		return BEER;
	else if (RATIO_BEER * 100 <= num && num < (RATIO_CAPPUCCINO + RATIO_BEER) * 100)
		return CAPPUCCINO;
	//we know that the remaining proportion is due to RATIO_HOT_CHOCOLATE from initial assert()
	return HOT_CHOCOLATE;
}
/**
 * full constructor with single particle, as template
 */
Emitter::Emitter(Vector3df loc, Particle part, int particleCount, float birthRate, 
                 Vector3df emissionVec, Vector3df emissionSpd, float sprayRadius, bool isContinous):
loc(loc), part(part), particleCount(particleCount), birthRate(birthRate), emissionVec(emissionVec), emissionSpd(emissionSpd), sprayRadius(sprayRadius), isContinous(isContinous) {
    
    // convert to unit direction
    emissionVec.normalize();
    // mult unit vector by magnitude
    emissionVec *= emissionSpd;
    
    // add emitter location to particle's current location (which is probably 0,0,0)
    part.loc += loc;
    //part.loc.y +=.9;
    
    // fill Particle vector with Particle template copies
    //push_back copies
    for(int i=0; i<particleCount; i++){
        parts.push_back(part);
        parts[i].dim = Dimension3d(getRand(part.dim.w),getRand(part.dim.w), getRand(part.dim.w));
    }
    init();
}
Beispiel #12
0
QString QuestionShow::test(int size)
{
    QString tmp = "\nLiczby losowe dla rozmiaru listy ";
    tmp += QString::number(size);
    tmp += ": ";

    for (int i = 0; i < 10; i++){
        tmp += QString::number(getRand(size));
        tmp += ", ";
    }
    return tmp;
}
Beispiel #13
0
int matchClassifiers( unsigned char *condition , Person p[], int position){
    int c;
    int i;
    double bidSum = 0.0;
    int matchFound = 0;
    
    /* Match condition with the list of classifiers */
    for (c = 0 ; c < MAX_CLASSIFIERS ; c++) {
        
        p[position].list[c].match = 0;
        
        for (i = 0 ; i < MAX_COND_WIDTH ; i++) {
            if (!match(p[position].list[c].condition[i], condition[i])) break;
            
        }
        //std::cout << "ioioioioioio i = " << i << "max cond witch = " << MAX_COND_WIDTH << std::endl;
        if (i == MAX_COND_WIDTH) {
            p[position].list[c].match = 1;
            p[position].list[c].bid = RISK_FACTOR * p[position].list[c].strength * p[position].list[c].specificity;
            //std::cout << "-=-==--bid should be this" << RISK_FACTOR * p[position].list[c].strength * p[position].list[c].specificity << std::endl;
            //std::cout << "-=-=-=actual bis is " << p[position].list[c].bid << std::endl;
            bidSum += p[position].list[c].bid;
            matchFound = 1;
        }
        
    }
    
    if (matchFound) {
        
        int tries = MAX_CLASSIFIERS;
        
        c = getRand(MAX_CLASSIFIERS);
        while (1) {
            
            if (p[position].list[c].match) {
                if ( (p[position].list[c].bid / bidSum) > getSRand()) break;
                if ( --tries == 0) break;
            }
            
            if (++c >= MAX_CLASSIFIERS) c = 0;
            
        }
        
    } else {
        
        if (c == MAX_CLASSIFIERS) {
            c = createCoveringClassifier( -1, condition , p, position);
        }
        
    }
    
    return c;
}
Beispiel #14
0
int main(int argc, char ** argv)
{
    int start = 1;
    int end = 1000000;
    int step = 100;
    ofstream os(argv[1]);
    for(int i=start; i<=end; i+=step)
    {
        Sequence a(i);
        Sequence b(i);
        for(int j=0; j<i; j++)
        {
            Point rtpt(getRand(),getRand(),getRand());
            a.set(j+1, rtpt);
            Point rtpt2(getRand(),getRand(),getRand());
            b.set(j+1, rtpt2);
        }
        AlcsRmsdSolver ads;
        double rmsd = ads.calcRmsdSeq(&a, &b);
        double minrmsd = rmsd/10;
        clock_t start = clock();
        ads.solve2(&a, &b, minrmsd);
        clock_t duration = clock() - start;
        os<<i<<"\t"<<duration<<endl;
    }
    os.close();
    return 0;
}
Beispiel #15
0
void EightHZDanceStrategy::step(double delta, bool firstRun) {
    if (timer > 0)
        timer -= delta;    
    
    if (firstRun)
        reset();
    
    switch (currentTask) {
        case Task1: {
            
            // Move back
            control->move(-10);
            
            if (timer <= 0) {
                timer = 0.7;
                currentTask = Task2;
                
            }
            break;
        }
        
        case Task2: {
            
            // Move half distance front
            control->move(10);
            
            if (timer <= 0) {
                timer = 1;
                currentTask = Task3;
            }
            break;
        }
        
        case Task3: {
            control->stop();  
            
            if (timer <= 0) {
                timer = 0.6 + 0.5 * getRand();
                currentTask = Task4;
            }           
            break;
        }
        
        case Task4: {
            control->turn(30);
            if (timer <= 0) {
                started=false;
            } 
            break;      
        }
    }
}
Beispiel #16
0
void HalfHZDanceStrategy::step(double delta, bool firstRun) {
    if (timer > 0)
        timer -= delta;    
    
    if (firstRun)
        reset();
    
    switch (currentTask) {
        case Task1: {
            
            // Move back
            control->move(-10);
            
            if (timer <= 0) {
                timer = 1.8;
                currentTask = Task2;
            }
            break;
        }
        
        case Task2: {
            
            // Turn left 360
            control->turn(-50);
            
            if (timer <= 0) {
                currentTask = Task3;
                timer = 1;
            }
            break;
        }
        
        case Task3: {
            control->stop();  
            
            if (timer <= 0) {
                timer = 0.6 + 0.5 * getRand();
                currentTask = Task4;
            }           
            break;
        }
        
        case Task4: {
            control->turn(30);
            if (timer <= 0) {
                started=false;
            } 
            break;      
        }
    }
}
int main(int argc, char* argv[])
{
	start();
	double min=0.00001, max=1.0;

	

	double iterations;
	double x,y,z,pi;
	int i,count=0;
	int j;
	
	
	iterations = atof(argv[1]);
	

	for(i=0;i<iterations;i++) 
	
	
	{
		x = getRand(min,max);
		
		
		y = getRand(min,max);
		z = x*x+y*y;
		if (z<=1) count++;
		
		
	}
	
	
	pi=(double)count/iterations*4;
	
	
	printf("pi is %g \n",pi);
	
	stop();
}
// genInitTile()
// Description: generate initial tile in random empty block
void Game::genInitTile(){
    int randBlk = getRand() % m_grid.getEmptyBlkNo() + 1;
    
    for(int i = 0;i < GRID_SIZE;i++){             
        if(m_grid[i] == EMPTY)
            randBlk--;
        if(randBlk == 0){
            m_grid.setBlock(i, getNextTile());
            setNextTile();
            return;
        }
    }
    assert(FALSE);
}    
Beispiel #19
0
void main () {

	unsigned int *image;
	image = (unsigned int*) malloc (WIDTH * HEIGHT * sizeof (unsigned int));


	int i;		// COUNTER FOR WIDTH

#pragma omp parallel for
	for (i=0; i<NPOINTS; i++) {
		double cx = getRand (XMIN, XMAX); //XMIN + i * (XMAX-XMIN) / (WIDTH - 1.0);
		double cy = getRand (YMIN, YMAX); //YMIN + j * (YMAX-YMIN) / (HEIGHT - 1.0);
		double x = 0.0;
		double y = 0.0;
		unsigned int count = 0;
		do {
			if (count == 100000) break;
			count++;
			N (&x, &y, cx, cy);
			int I, J;
			getIJ (&I, &J, x, y);
			if (I>=0 && I < WIDTH && J>=0 && J < HEIGHT) 
				IMAGE(I,J)++;
		} while (norm (x, y) < 4.0);

	}

	int j;
	for (j=0; j<HEIGHT; j++) {	
		for (i=0; i<WIDTH; i++)
			printf ("%u  ", IMAGE(i,j));
		printf ("\n");
	}

	free (image);

}
Beispiel #20
0
	float RandomGen::getRandFloat(float fRangle) {
		//static	float fToRand;
		//fToRand = fRangle;
		//if (0 > fToRand) {
		//	fToRand = -fToRand;
		//}
		//static const float MAXRANGLE = 1000000;
		//unsigned int uiRand = getRand((unsigned int)(fToRand * MAXRANGLE));
		//float fRet = (float)uiRand/MAXRANGLE;
		//if (0 > fRangle) {
		//	fRet = -fRet;
		//}

		return (float) getRand() / (float) getRandMax() * fRangle ;
	}
Beispiel #21
0
void rippleGenerateAddress(std::string& address, std::string& secret)
{
	RippleAddress naSeed;
	RippleAddress naAccount;

	uint128 key;
	getRand(key.begin(), key.size());

	naSeed.setSeed(key);
	RippleAddress naGenerator = createGeneratorPublic(naSeed);
	naAccount.setAccountPublic(naGenerator.getAccountPublic(), 0);

	secret = naSeed.humanSeed();
	address = naAccount.humanAccountID();
}
Beispiel #22
0
// Get a random string
TCHAR* getStringValue()
{
	int size = int(getRand(1.0, 15.0));

	TCHAR* val = new TCHAR[size + 1];
	val[size] = _T('\0');

	// last letter is lower case
	val[--size] = _T('a') + int(getRand(0.0, 26.0));
	// first letter is upper case
	val[0] = _T('A') + int(getRand(0.0, 26.0));
	// Other letter are random, 1/6 spaces, 1/6 upper case, 2/3 lower case
	while (--size > 0) {
		int r = int(getRand(-26.0, 5.0 * 26.0));
		if (r < 0)
			val[size] = _T(' ');
		else if (r < 26)
			val[size] = _T('A') + r;
		else
			val[size] = _T('a') + r % 26;
	}

	return val;
}
/// Default Constructor. Initialises the position to zero.
/// The rotation around the Y axis is picked randomly to allow random
/// spinning of objects. Display lists are off by default
Renderable::Renderable()
{
	this->x = 0.0f;
	this->y = 0.0f;
	this->z = 0.0f;
	
	this->rx = 0.0f;
	this->ry = getRand(0.0f, 360.0f);
	this->rz = 0.0f;

	this->sx = 1.0f;
	this->sy = 1.0f;
	this->sz = 1.0f;

	isList = false;
}
Beispiel #24
0
int nextWord(int word)
{
    int nextWord = (word +1);
    int max = sumVector[word];
    int lim, sum = 0;

    lim = getRand(max)+1;
    while (nextWord != word){
        nextWord = nextWord % curWord;
        sum += bigramArray[word][nextWord];
        if (sum>=lim) {
            return nextWord;
        }
        nextWord++;
    }
    return nextWord;
}
Beispiel #25
0
bool GameLayer::init() {
	if (!Layer::init()) {
		return false;
	}
	this->setTouchEnabled(true);
	Size winSize = Director::getInstance()->getWinSize();
	char buff[15];
	int id = getRand(1, 5);
	sprintf(buff, "img_bg_%d.jpg", id);
   
    //readInZipFileName();
    
	auto over = Sprite::create(buff);
	over->setPosition(Point(winSize.width / 2, winSize.height / 2));
	this->addChild(over);
	return true;
}
Beispiel #26
0
		TEST_F(RectDiff, Divide) {
			// ランダムなテスト範囲
			auto rd = getRand();
			auto randI = rd.template getUniformF<int>();
			constexpr int MaxRange = 100;
			const Size size(randI({1, MaxRange}),
							randI({1, MaxRange}));
			bool imap[MaxRange*2][MaxRange*2];
			const auto randX = rd.template getUniformF<int>({-size.width/2, size.width/2}),
						randY = rd.template getUniformF<int>({-size.height/2, size.height/2});
			constexpr int NItr = 0x100;
			for(int i=0 ; i<NItr ; i++) {
				std::memset(imap, 0, sizeof(imap));
				// テスト範囲以下の矩形をランダムな位置に置く
				const auto rect = RandomRect(randX, randY);
				int area = 0;
				ASSERT_NO_FATAL_FAILURE(
					rect::DivideRect(
						size,
						rect,
						[&size, &area, &imap](const Rect& g, const Rect& l){
							ASSERT_NO_THROW(g.checkValidness());
							ASSERT_NO_THROW(l.checkValidness());
							// グローバルとローカル矩形の面積は同じ
							ASSERT_EQ(g.area(), l.area());
							// ローカル座標がテスト範囲を出ていないか
							ASSERT_TRUE(IsInRange(l.x0, 0, size.width));
							ASSERT_TRUE(IsInRange(l.x1, 0, size.width));
							ASSERT_TRUE(IsInRange(l.y0, 0, size.height));
							ASSERT_TRUE(IsInRange(l.y1, 0, size.height));
							// 矩形を塗りつぶしていき、重なりや面積が違っていなければOK
							for(int i=g.y0 ; i<g.y1 ; i++) {
								for(int j=g.x0 ; j<g.x1 ; j++) {
									auto& im = imap[i+MaxRange][j+MaxRange];
									ASSERT_FALSE(im);
									im = true;
								}
							}
							area += g.area();
						}
					)
				);
				ASSERT_EQ(rect.area(), area);
			}
		}
Beispiel #27
0
// 0 -> perfect; 10 -> they will kill each other
void genMatrix(int * D, int n)
{
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
		{
			if(i < j)
			{
				// force a 0 cost solution
				if ( i%2==0 && i==(j-1) ) D[(i*n)+j] = 0;
				else D[(i*n)+j] = getRand(0, 11);
			}
			else
			{	
				// the lower triangle doesnt matter
				D[(i*n)+j] = -1;
			}
		}
}
Beispiel #28
0
int buildSentence(void)
{
    int word = START_SYMBOL;
    int max = 0;
    printf("\n");

    word = nextWord(word);

    while (word != END_SYMBOL) {
        printf("%s ", wordVector[word]);
        word = nextWord(word);
        max += getRand(12)+1;
        if (max>=100) break;
    }
    printf("%c. \n\n", 8);

    return 0;
}
Beispiel #29
0
// generates a random solution
void genSolution(int * a, int n)
{
	for(int i=0; i<n; i++)
	{
		if(a[i] == -1)
		{

			int p = getRand(0, n);

			if( !contains(a, p, n) && i!=p )
			{
				a[i] = p;
				a[p] = i;
			}
			else i--;
		}
	}
}
Beispiel #30
0
		TEST_F(RectDiff, Incremental) {
			// ランダムなテスト範囲
			auto rd = getRand();
			constexpr int MaxRange = 100;
			const auto randMove = rd.template getUniformF<int>({-MaxRange, MaxRange});
			const auto randW = rd.template getUniformF<int>({-MaxRange, MaxRange});
			constexpr int NItr = 0x100;
			for(int i=0 ; i<NItr ; i++) {
				// テスト範囲以下の矩形をランダムな位置に置く
				const auto rect = RandomRectNZ(randW, randW);
				// 矩形を移動
				const int mvx = randMove(),
						mvy = randMove();
				const auto rect2 = rect.move(mvx, mvy);
				int area0 = 0;
				int nResult = 0;
				Rect result[2];
				rect::IncrementalRect(
					rect,
					mvx,
					mvy,
					[&area0, &result, &nResult, &rect, &rect2](const Rect& r){
						if(nResult != 0) {
							// 既に算出された差分矩形同士は重ならない
							ASSERT_FALSE(r.hit(result[0]));
						}
						// 元の矩形と差分矩形は重なっていない
						ASSERT_FALSE(r.hit(rect));
						// 移動後の矩形と差分矩形は重なる
						ASSERT_TRUE(r.hit(rect2));

						area0 += r.area();
						result[nResult++] = r;
					}
				);
				// 前後それぞれの矩形の面積 - 重なっている矩形の面積 == 差分矩形の面積
				int area1;
				if(const auto cr = rect.cross(rect2)) {
					area1 = rect.area() - cr->area();
				} else
					area1 = rect.area();
				ASSERT_EQ(area1, area0);
			}
		}