Пример #1
0
double gauss_diff(){
  static pfi::math::random::random<mersenne_twister> r;
  static double last_val = r.next_gaussian();
  double cur_val = r.next_gaussian();
  double ret = (last_val-cur_val)/sqrt(2.0);
  last_val=cur_val;
  return ret;
}
Пример #2
0
ratio<int> gen_ratio(){
  static pfi::math::random::random<mersenne_twister> r;
  int num=r.next_int(0,1000)-500;
  int den=r.next_int(0,1000)-500;
  if(den>=0)++den;
  if(num>=0)++num;
  return ratio<int>(num,den);
}
Пример #3
0
ppm<color> rand_ppm(image_coordinate_t w=Rand.next_int(50,200),
		    image_coordinate_t h=Rand.next_int(50,200),
		    rgb<color> bc=rgb<color> 
		    (Rand.next_int(256),Rand.next_int(256),Rand.next_int(256))){

  ppm<color> p(w,h,bc);
  for(int y=0;y<p.height();++y){
    for(int x=0;x<p.width();++x){
      p(x,y)=rand_rgb<color>();
    }
  }
  return p;
}
Пример #4
0
TEST(ppm,access_by_complex_and_vector){
  for(int n=0;n<N;++n){
    ppm<uint8_t> p=rand_ppm<uint8_t>();
    for(int i=0;i<1000;++i){
      double
	x=Rand.next_double(-10,p.width()+10),
	y=Rand.next_double(-10,p.height()+10);
      complex<double> z(x,y);
      vector2<double> pt(x,y);
      EXPECT_TRUE(p(x,y)==p(z));
      EXPECT_TRUE(p(x,y)==p(pt));
    }
  }
}
Пример #5
0
TEST(ppm,out_of_range_access_safety){
  for(int n=0;n<N;++n){
    ppm<uint8_t> p=rand_ppm<uint8_t>(), p_orig=p;
    for(int t=0;t<100;++t){
      int x,y; 
      *((uint32_t*)&x)=Rand.next_int();
      *((uint32_t*)&y)=Rand.next_int();
      EXPECT_TRUE(p(x,y)==p.bgcolor);
      p(x,y)=rand_rgb<uint8_t>();
    }

    for(int y=0;y<p.height();++y){
      for(int x=0;x<p.width();++x){
	p(x,y)==p_orig(x,y);
      }
    }
  }
}
Пример #6
0
rgb<color> rand_rgb(){
  return rgb<color>((color)Rand.next_int(256),
		    (color)Rand.next_int(256),
		    (color)Rand.next_int(256));
}
Пример #7
0
double gauss_shifted(){
  static pfi::math::random::random<mersenne_twister> r;
  return (r.next_gaussian(42.0, 24.0)-42.0)/24.0;
}
Пример #8
0
double gauss(){
  static pfi::math::random::random<mersenne_twister> r;
  return r.next_gaussian();
}
Пример #9
0
double uniform(){
  // unform distribution
  static pfi::math::random::random<mersenne_twister> r;
  return r.next_double(-sqrt(3.0),sqrt(3.0));
}