DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T m

⟦17d9017d4⟧ TextFile

    Length: 644 (0x284)
    Types: TextFile
    Names: »mkperm.c«

Derivation

└─⟦db229ac7e⟧ Bits:30007240 EUUGD20: SSBA 1.2 / AFW Benchmarks
    └─⟦this⟧ »EUUGD20/AFUU-ssba1.21/ssba1.21E/musbus/mkperm.c« 
    └─⟦this⟧ »EUUGD20/AFUU-ssba1.21/ssba1.21F/musbus/mkperm.c« 

TextFile

#include <stdio.h>
#ifndef lint
static char RCSid[] = "$Header: mkperm.c,v 1.2 87/06/22 14:32:26 kjmcdonell Beta $";
#endif

int rand();
void srand();

main(argc, argv)
int	argc;
char	*argv[];
{
	int	n;	/* generate a permutation of {1,2,3,...,n} */
	int	i;
	unsigned	t;
	char	*mask;

	if (argc > 2 && strcmp(argv[1], "-s") == 0) {
		t = atoi(argv[2]);
		if (t < 16)
			t = 1 << t;
		srand(t);
		argv++;
		argv++;
	}
	n = atoi(argv[1]);
	mask = (char *)malloc(n);

	for (i=0; i<n; i++)
		mask[i] = '\0';
	for (i=0; i<n; i++) {
		do {
			t = rand() % n;
		} while (mask[t]);
		mask[t] = '\1';
		printf("%d ", t+1);
	}
	putchar('\n');
	exit(0);
}