Why do I feel like writing a one-dimensional life game rule can make a random number generator that looks very random and actually quite random ....
This is the code:
1#include <cstdio>2#include <fstream>3#include <iostream>4 5#include <cstdlib>6#include <cstring>7#include <algorithm>8#include <cmath>9 Ten#include <queue> One#include <vector> A#include <map> -#include <Set> -#include <stack> the#include <list> - -typedef unsignedint UINT; -typedefLong Long intll; +typedef unsignedLong Long intull; -typedefDoubledb; + A using namespacestd; at -InlineintGetint () - { - intres=0; - CharC=GetChar (); - BOOLMi=false; in while(c<'0'|| C>'9') mi= (c=='-'), c=GetChar (); - while('0'<=c && c<='9') res=res*Ten+c-'0', c=GetChar (); to returnMi? -Res:res; + } - inline ll getll () the { *ll res=0; $ CharC=GetChar ();Panax Notoginseng BOOLMi=false; - while(c<'0'|| C>'9') mi= (c=='-'), c=GetChar (); the while('0'<=c && c<='9') res=res*Ten+c-'0', c=GetChar (); + returnMi? -Res:res; A } the +DB eps=1e- the; -InlineBOOLfeq (db a,db B) ${returnFabs (A-B) <EPS;} $ -Template<typename type> -Inline Type avg (ConstType A,ConstType b) the{returnA + ((b-a)/2); } - Wuyi //============================================================================== the //============================================================================== - //============================================================================== Wu //============================================================================== - About intn,m; $ - inta[2][1005000]; - - BOOLrd[1005000]; A intrt=0; + intLastrand=7; the intGetrand () - { $ intres=0; the for(intI=0;i<Ten; i++) res+= (rd[lastrand+ (i<<1)]<<i); thelastrand++; the returnRes; the } - in the the intMain () About { theFreopen ("In.txt","R", stdin); theFreopen ("OUT.txt","W", stdout); the +n=getint (); - the intmid=n*2, s=0;Bayia[0][mid]=1; the for(intI=1; i<n;i++) the { - for(intj=mid-i;j<=mid+i;j++) -a[!s][j]=a[s][j]+a[s][j-2]^a[s][j+1]-a[s][j]^a[s][j+1]+a[s][j+1]; thes^=1; the the for(intj=mid-i;j<=mid+i;j++) rd[rt++]= (a[s][j]<0); the } - the for(intI=0;i<12500; i++) Cout<<getrand () <<','; the the 94 return 0; the}View Code
The seed can be set Lastrand, can also be set Lastrand increment, even to take what data calculate random number ...
The following is a random number of 12,500 that generates 0 to 1023 according to the above code.
Looks like there's a lot?.... left. But it should be enough .... It's random .....
The next task is to write a class that can be used.
Allocate and the like are the most annoying embarrassment ...
And then here's the fun stuff ...
This is the result of adding a%611 after the Cout<<getrand (). This tells us never to take the random number of native models! ......
But I want a random number between 0 and 611?
Uh.... It seems a feasible way to use a double to correspond to the range of [0,1] in the original interval.
It seems that the constant is a bit big, I dream when think there is no better ...
Some kind of unspeakable secret between life games and random numbers