drand.c

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 1.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 OpenFX Development Team
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019 You may contact the OpenFX development team via elecronic mail
00020 at core@openfx.org, or visit our website at http://openfx.org for
00021 further information and support details.
00022 -- */
00023 
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026 #include <math.h>
00027 
00028 #define imod(z,a) ((z) - ((z)/(a))*(a))
00029 
00030 long IX=9123,IY=8844,IZ=20846; /* initial state */
00031 
00032 void dSeedRandom(long i){
00033  srand(i); IX=rand(); IY=rand(); IZ=rand();
00034 }
00035 
00036 double dRandom(void){
00037  IX=imod(171*IX,30269);
00038  IY=imod(172*IY,20207);
00039  IZ=imod(170*IZ,30323);
00040  return (double)fmod((double)IX/30269.0+
00041                      (double)IY/30307.0+
00042                      (double)IZ/30323.0,1.0);
00043 }
00044 
00045 #define N 1000
00046 
00047 void main(){
00048  int i;
00049  for(i=0;i<N;i++){
00050   printf("{%lf,%lf,%lf},{%lf,%lf,%lf},\n",dRandom(),dRandom(),dRandom(),
00051   dRandom(),dRandom(),dRandom());
00052  }
00053 }
Generated on Tue Jan 28 06:18:32 2014 for OpenFX by  doxygen 1.6.3