예제 #1
0
void genData(FILE *fn, int nVec, float xVar)
{
    float xMax = 1.1;
    float xMin = -xMax;
    float xRange = (xMax - xMin);

    // write header info
    uint32_t nInput=2;
    fwrite(&nInput,sizeof(int32_t), 1, fn);
    uint32_t nOutput=0;
    fwrite(&nOutput,sizeof(int32_t), 1, fn);
    uint32_t nExamples=nVec;
    fwrite(&nExamples,sizeof(int32_t), 1, fn);

    for(int i=0; i < nVec; i++) {
        float t = xRange * f_rand();
        float z1 = t +  xVar * f_rand();
#ifdef USE_LINEAR
        float z2 = t +  xVar * f_rand();
#else
        float z2 = t*t*t +  xVar * f_rand();
#endif
        fwrite(&z1, sizeof(float), 1, fn);
        fwrite(&z2, sizeof(float), 1, fn);
    }
}
예제 #2
0
bool TestExtMath::test_rand() {
  f_rand();
  VERIFY(f_rand(5, 15) >= 5);
  VERIFY(f_rand(5, 15) <= 15);

  int64_t n = f_rand(10000000000LL, 19999999999LL);
  VERIFY(n >= 10000000000LL);
  VERIFY(n <= 19999999999LL);

  return Count(true);
}
예제 #3
0
void SimpleCounter::Count(const string &name) {
  if (Enabled) {
    int count = ++s_counter->m_counters[name];
    if (SampleStackCount > 0) {
      assert(StackTrace::Enabled);
      vector<string> &stackVec = s_counter->m_stacks[name];
      if ((int)stackVec.size() < SampleStackCount ||
          f_rand(0, count - 1) < SampleStackCount) {
        StackTrace st;
        if ((int)stackVec.size() < SampleStackCount) {
          // skip StackTrace methods and the Count() call.
          stackVec.push_back(st.hexEncode(3, 3 + SampleStackDepth));
        } else {
          // skip StackTrace methods and the Count() call.
          stackVec[f_rand(0, SampleStackCount - 1)] =
            st.hexEncode(3, 3 + SampleStackDepth);
        }
      }
    }
  }
}
예제 #4
0
static void php_array_data_shuffle(std::vector<ssize_t> &indices) {
  int n_elems = indices.size();
  if (n_elems > 1) {
    int n_left = n_elems;
    while (--n_left) {
      int rnd_idx = f_rand(0, n_left);
      if (rnd_idx != n_left) {
        ssize_t temp = indices[n_left];
        indices[n_left] = indices[rnd_idx];
        indices[rnd_idx] = temp;
      }
    }
  }
}
예제 #5
0
Variant ArrayUtil::RandomKeys(const Array& input, int num_req /* = 1 */) {
  int count = input.size();
  if (num_req <= 0 || num_req > count) {
    raise_warning("Second argument has to be between 1 and the "
                  "number of elements in the array");
    return init_null();
  }

  if (num_req == 1) {
    // Iterating through the counter is correct but a bit inefficient
    // compared to being able to access the right offset into array data,
    // but necessary for this code to be agnostic to the array's internal
    // representation.  Assuming uniform distribution, we'll expect to
    // iterate through half of the array's data.
    ssize_t index = f_rand(0, count-1);
    ssize_t pos = input->iter_begin();
    while (index--) {
      pos = input->iter_advance(pos);
    }
    return input->getKey(pos);
  }

  std::vector<ssize_t> indices;
  indices.reserve(count);
  auto pos_limit = input->iter_end();
  for (ssize_t pos = input->iter_begin(); pos != pos_limit;
       pos = input->iter_advance(pos)) {
    indices.push_back(pos);
  }
  php_array_data_shuffle(indices);

  PackedArrayInit ret(num_req);
  for (int i = 0; i < num_req; i++) {
    ssize_t pos = indices[i];
    ret.append(input->getKey(pos));
  }
  return ret.toVariant();
}
예제 #6
0
int _tmain(int argc, _TCHAR* argv[])
{
	system("title LABIRINTiT 1x - PRODUÇÃO - RODRIGO MARTINS ! FELIPE MASIOLI");
	int tecla,variado;
	int result;
	char mapa_a[10][40], jogador[100];
    int i, j,pont=0;
	clock_t start, end;
    double elapsed;

	FILE *arquivo;
	srand(time(NULL));
	variado = random(0,3);
	
	arquivo = f_rand(variado);	

	printf("\n\n\t\tLABIRINTiT 1x");
	printf("\n\n\tQual o seu nome jogador???\n\t\t");
	scanf("%s", jogador);


	start = clock();      
	do{
		system(LIMPARTELA);

		//printf("\t\t\tLABIRINTiT 1x\n\n");

		/* Abre o arquivo */
		if(!arquivo)
		  {
			printf("Erro ao abrir arquivo!!!");
			exit(1);
		  }	
		/* Escreve a matriz no arquivo */
		for (i=0; i<10; i++)
		{
			for (j=0; j<40; j++)
			{
				fscanf(arquivo, "%d",&mapa_a[i][j]);
			}
		}
		mapa_a[linha_atual][coluna_atual] = nome;
		for(i=0;i<10;i++)
		{
			for(j=0;j<40;j++)
				printf("%c",mapa_a[i][j]);
			puts("");
		}
/* O Mapa */
        printf("\n##################### L A B I R I N T i T - 1x ################################\n");
        printf("\n\n    ( %c )\n\n( %c ) + ( %c )\n\n    ( %c )\n",30,17,16,31); /* Imprime as direcoes */
        printf("\nPressione ESC para sair\n");
        printf("\n------------------------------------------------------------------------------\n");

        tecla = getch();
		
        if ( tecla == ACIMA ) {
	     	  printf("%c",mapa_a[linha_atual][coluna_atual]);
		      mapa_a[linha_atual][coluna_atual]=0;
		      linha_atual = linha_atual - 1;
		      printf("%c",mapa_a[linha_atual][coluna_atual]);
          /* Se não for chao ou grama ele volta pra posicao anterior */
              if ((mapa_a[linha_atual][coluna_atual] != 0) && (mapa_a[linha_atual][coluna_atual] != 176) && (mapa_a[linha_atual][coluna_atual] != 4)) 
			  {
					linha_atual = linha_atual + 1;
		      }
        }
        if ( tecla == ABAIXO ) {
		      printf("%c",mapa_a[linha_atual][coluna_atual]);
		      mapa_a[linha_atual][coluna_atual]=0;
              linha_atual = linha_atual + 1;
          /* Se não for chao ou grama ou saida ele volta pra posicao anterior */
              if ((mapa_a[linha_atual][coluna_atual] != 0) && (mapa_a[linha_atual][coluna_atual] != 176) && (mapa_a[linha_atual][coluna_atual] != 4)) 
			  {
					linha_atual = linha_atual - 1;
			  }
        }
        if ( tecla == DIREITA ) {
              printf("%c",mapa_a[linha_atual][coluna_atual]);
              mapa_a[linha_atual][coluna_atual]=0;
              coluna_atual = coluna_atual + 1;
          /* Se não for chao ou grama ou saida ele volta pra posicao anterior */
              if ((mapa_a[linha_atual][coluna_atual] != 0) && (mapa_a[linha_atual][coluna_atual] != 176) && (mapa_a[linha_atual][coluna_atual] != 4)) 
			  {
					coluna_atual = coluna_atual - 1;
              }
        }
        if ( tecla == ESQUERDA ) {
              printf("%c",mapa_a[linha_atual][coluna_atual]);
              mapa_a[linha_atual][coluna_atual]=0;
              coluna_atual = coluna_atual - 1;
          /* Se não for chao ou grama ou saida ele volta pra posicao anterior */
              if ((mapa_a[linha_atual][coluna_atual] != 0) && (mapa_a[linha_atual][coluna_atual] != 176) && (mapa_a[linha_atual][coluna_atual] != 4)) 
			  {
					coluna_atual = coluna_atual + 1;
              }
        }
		if (mapa_a[linha_atual][coluna_atual] !=4 )
	    {
			pont++;
	    }
       
	}while(  (tecla != ESC) && (mapa_a[linha_atual][coluna_atual] != 4) );
	
	result = pont/2;
	end = clock(); 
	elapsed = ((double) (end - start)) / CLOCKS_PER_SEC;
		
	if (mapa_a[linha_atual][coluna_atual] == 4)
	{	
	    printf ("%s,\n",jogador);

			if (variado == 0)
			{
				if (result == 34)
				{
					printf ("Voce andou %d vezes ...\n Gastou um tempo de %0.0f segundos...\n", result, elapsed);
					printf("\t\tVoce foi excelente!!!\n");
					printf ("\t!!!!!!!!!!!!!!PARABENSSSSSSSSS!!!!!!!!!!!!!!\n\n");
				}
				if (result > 34)
				{
					printf ("Voce andou %d vezes ...\n Gastou um tempo de %0.0f segundos...\n", result, elapsed);
					printf("\tVoce prescisa melhorar!!!\n");
				}
			}
			if (variado == 1)
			{
				if (result == 51)
				{
					printf ("Voce andou %d vezes ...\n Gastou um tempo de %0.0f segundos...\n", result, elapsed);
					printf("\t\tVoce foi excelente!!!\n");
					printf ("\t!!!!!!!!!!!!!!PARABENSSSSSSSSS!!!!!!!!!!!!!!\n\n");
				}
				if (result > 51)
				{
					printf ("Voce andou %d vezes ...\n Gastou um tempo de %0.0f segundos...\n", result, elapsed);
					printf("\tVoce prescisa melhorar!!!\n");
				}
			}
			if (variado == 2)
			{
				if (result == 68)
				{
					printf ("Voce andou %d vezes ...\n Gastou um tempo de %0.0f segundos...\n", result, elapsed);
					printf("\t\tVoce foi excelente!!!\n");
					printf ("\t!!!!!!!!!!!!!!PARABENSSSSSSSSS!!!!!!!!!!!!!!\n\n");
				}
				if (result > 68)
				{
					printf ("Voce andou %d vezes ...\n Gastou um tempo de %0.0f segundos...\n", result, elapsed);
					printf("\tVoce prescisa melhorar!!!\n");
				}
			}
			if (variado == 3)
			{
				if (result == 71)
				{
					printf ("Voce andou %d vezes ...\n Gastou um tempo de %0.0f segundos...\n", result, elapsed);
					printf("\t\tVoce foi excelente!!!\n");
					printf ("\t!!!!!!!!!!!!!!PARABENSSSSSSSSS!!!!!!!!!!!!!!\n\n");
				}
				if (result > 71)
				{
					printf ("Voce andou %d vezes ...\n Gastou um tempo de %0.0f segundos...\n", result, elapsed);
					printf("\tVoce prescisa melhorar!!!\n");
				}
			}

		system("pause");
		system(acaba);
	}		

	fclose(arquivo);
	return 0;
}