permute.c
/*
* Copyright (c) 2000, 2001 Thomas E. Burge. All rights reserved.
*
* Affine (R) is a registered trademark of Thomas E. Burge
*
* THIS SOFTWARE IS DISTRIBUTED "AS-IS" WITHOUT WARRANTY OF ANY KIND
* AND WITHOUT ANY GUARANTEE OF MERCHANTABILITY OR FITNESS FOR A
* PARTICULAR PURPOSE.
*
* In no event shall Thomas E. Burge be liable for any indirect or
* consequential damages or loss of data resulting from use or performance
* of this software.
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that the following copyright notices and this permission notice appear in
* all copies of the software and related documentation:
*
* The Affine (R) Libraries and Tools are
* Copyright (c) 1995-2001 Thomas E. Burge.
* All rights reserved.
* Affine (R) is a registered trademark of Thomas E. Burge.
*
* Also refer to any additional requirements presently set by Pixar
* in regards to the RenderMan (R) Interface Procedures and Protocol.
*
*
* Affine Toolkit
*
* FILE: permute.c
*
* DESCRIPTION: Prints a table of randomly distributed numers from 0 to 2048.
*
* References:
*
* History:
*
*
* The RenderMan (R) Interface Procedures and Protocol are:
* Copyright 1988, 1989, Pixar
* All Rights Reserved
*
* RenderMan (R) is a registered trademark of Pixar
*/
#include <stdio.h>
static unsigned int idum=1;
void setseed(unsigned int seed)
{
idum = seed;
}
int getrandom( int max )
{
/* Numerical Recipes in C, Second Edition, page 284. */
idum = 1664525*idum + 1013904223;
max++;
return idum % max;
}
int main(int argc, char **argv)
{
unsigned int P[2048];
int i,j,k,n;
if (argc==2)
setseed(atoi(argv[1]));
for (i=0;i<2048;i++)
P[i] = i;
for (n=0;n<11;n++)
{
for (i=0;i<2048;i++)
{
j = getrandom(2047);
k = P[j];
P[j] = P[i];
P[i] = k;
}
}
printf(" ");
for (i=0;i<2048;i++)
{
printf("%4u, ",P[i]);
if (i%10==9)
printf("\n ");
}
printf("\n");
return 0;
}
[Affine Toolkit]
[RIB Utilities]
[Bitmap Utilities]
[Handy Little Utilities]
[Libraries]
[Using the Libraries]