|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - downloadIndex: ┃ T p ┃
Length: 1097 (0x449) Types: TextFile Names: »perm.c«
└─⟦87ddcff64⟧ Bits:30001253 CPHDIST85 Tape, 1985 Autumn Conference Copenhagen └─ ⟦this⟧ »cph85dist/stat/src/perm.c«
#include "unixstat.h" PGM(perm,Randomly Permut Lines,5.0,3/4/85) /* Copyright (c) 1982 Gary Perlman (see Copyright file) */ #ifdef SMALL_MEM #define MAXLINES 250 #else #define MAXLINES 1000 #endif main (argc, argv) char **argv; { char *lptr[MAXLINES]; int nlines; int lineno; ARGV0; ERROPT (1) checkstdin (Argv0); nlines = readlines (lptr, MAXLINES); strpermut (lptr, nlines); for (lineno = 0; lineno < nlines; lineno++) puts (lptr[lineno]); exit (0); } readlines (lptr, maxlines) char **lptr; int maxlines; { int nlines; char line[BUFSIZ]; unsigned len; for (nlines = 0; gets (line); nlines++) { if (nlines == maxlines) ERRMANY (lines, maxlines) len = strlen (line); if ((lptr[nlines] = malloc (len+1)) == NULL) ERRSPACE (lines) strcpy (lptr[nlines], line); } return (nlines); } strpermut (array, size) char *array[]; { int i, irand; char *temp; extern double Maxrand; initrand (); for (i = 0; i < size; i++) { irand = (int) (rand () / Maxrand * (size-i)) + i; temp = array[i]; array[i] = array[irand]; array[irand] = temp; } }