#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include <sys/timeb.h>
#include <sys/time.h> /* para usar as funções de tempo e alta def. */

void IniciaRand()
{	/* Substituir por uma funcao que tome tempo em ms */
	struct timeval tv;
	struct timezone tz;
	if ( gettimeofday(&tv, &tz) ){
		printf("Erro ao chamar a função 'gettimeofday': randomização será prejudicada.\n");
		srand(time(0));
	} else {
		srand(tv.tv_sec ^ tv.tv_usec);
	}
}

double rand0a1()
{
	/* Dividir pelo maior inteiro */
	/* Em ANSI C o maior *valor* que rand assume é def. como RAND_MAX */
	double resultado = (double) rand() / RAND_MAX;	
	if (resultado > 1.0)
		resultado = 1.0;
	return resultado;
}

void Permut(int A[], int n)
{
	int i, j, b;

	IniciaRand(); /* Funcao que Inicia a geracao de numeros randomicos */
	for (i = n - 1; i > 0; i--) {
		j = (i * rand0a1()) + 1;
		b = A[i];
		A[i] = A[j];
		A[j] = b;
	}
}

/* Multiplas definições de main....

int main()
{
	unsigned int x;
	int v[20];

	for (x = 0; x < 20; x++)
		v[x] = x;
	Permut(v, 20);
	for (x = 0; x < 20; x++)
		printf("%02d ", v[x]);
	printf("\n");
	return 0;
}*/
