random.c

/* $RCSfile$ $Revision$ $Date$ * * Copyright (c) 2000 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 is granted to include compiled versions of this code in * noncommercially sold software provided the following copyrights and * notices appear in all software and any related documentation: * * The Affine (R) Libraries and Tools are * Copyright (c) 1995, 1996, 1997, 1998 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. * * Those wishing to distribute this software commercially and those wishing * to redistribute the source code must get written permission from the * author, Thomas E. Burge. * * Basically for now, I would like folks to get the source code directly * from me rather than to have a bunch of different versions circulating * about. * * * Affine Toolkit * * FILE: random.c * * DESCRIPTION: Prints a table of random numbers. * * 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++; /* Can core dump if max is zero as a second paramter to mod. */ return idum % max; } int main(int argc, char **argv) { unsigned int P[2048]; int i,j,k; if (argc==2) setseed(atoi(argv[1])); for (i=0;i<2048;i++) P[i] = getrandom(0x7fffffff); printf(" "); for (i=0;i<2048;i++) { printf("%1.10g, ",(float)P[i]/(float)0x7fffffff); if (i%5==4) printf("\n "); } printf("\n"); return 0; }


[Affine Toolkit]
[RIB Utilities] [Bitmap Utilities] [Handy Little Utilities]
[Libraries] [Using the Libraries]