holas gente del foro quisiera que me ayuden con este problema que tengo esque la funcion rand casi siempre me bota los mismos numero quisiera que me dijeran como poder hacer que me bote numeros distinos...o existe otro metodo para sacar numeros al azar
ademas porque siempre me salen que (tiempo 2 -tiempo 1) siempre me salen 0 en todos los casos
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include<stdlib.h>
#include <time.h>
using namespace std;
int vector[1000000];
bool isEven(int n)
{
int math = n%2;
if(math==0)
return true;
else
return false;
}
unsigned int ciclo(unsigned int curValue, unsigned int count)
{
if(curValue == 1) return count;
if(isEven(curValue))
return ciclo(curValue/2, count+1);
else
return ciclo((curValue*3)+1, count+1);
}
unsigned int maxCiclo(unsigned long comienzo, unsigned long fin)
{
unsigned int curMax = 0;
if(comienzo> fin)
swap(comienzo, fin);//swap intercambia los valores si start> stop
for(unsigned int i=comienzo; i<=fin;i++)
{
unsigned int tempciclo;
if(vector[i] == 0)
{
tempciclo = ciclo(i, 1);
vector[i] = tempciclo;
}
else tempciclo = vector[i];
if(tempciclo>curMax)
curMax = tempciclo;
}
return curMax;
}
int getMilisegundos(clock_t c)
{
int tiempo=0;
tiempo = (int)((c/(double)CLOCKS_PER_SEC)*1000) ;
return tiempo;
}
int main(int argc, char *argv[])
{
clock_t t1, t2;
srand(time(NULL));
unsigned int comienzo;
unsigned int fin;
for(int i=0;i<1000;i++)
{
t1 = clock();
comienzo=i+1;
fin=(rand() % 10000);
maxCiclo(comienzo, fin);
t2 = clock();
printf("%d %d %f \n",comienzo,fin,getMilisegundos(t2-t1));
t1=t2=0;
}
system("PAUSE");
}