int generate_file(const char *dest_file, int rows, int cols) { FILE *fp; if(!(fp=fopen(dest_file,"w"))){ fprintf(stderr, "Can't open output file \"%s\"\n", dest_file); perror("Reason"); return ERRGEN; } for(int i=0; i<rows; ++i){ for(int j=0; j<cols; ++j) fprintf(fp, "%d ", (int)(uniform_deviate()*UPB)); putc('\n', fp); } if(ferror(fp)){ fprintf(stderr, "Error in writing to file \"%s\"\n", dest_file); perror("Reason"); return ERRGEN; } if(fclose(fp)){ fprintf(stderr, "Can't close output file \"%s\"\n", dest_file); perror("Reason"); return ERRGEN; } return 0; }
int dscr_explicit(void) { unsigned long i, dscr = 0; srand(getpid()); set_dscr(dscr); for (i = 0; i < COUNT; i++) { unsigned long cur_dscr, cur_dscr_usr; double ret = uniform_deviate(rand()); if (ret < 0.001) { dscr++; if (dscr > DSCR_MAX) dscr = 0; set_dscr(dscr); } cur_dscr = get_dscr(); if (cur_dscr != dscr) { fprintf(stderr, "Kernel DSCR should be %ld but " "is %ld\n", dscr, cur_dscr); return 1; } ret = uniform_deviate(rand()); if (ret < 0.001) { dscr++; if (dscr > DSCR_MAX) dscr = 0; set_dscr_usr(dscr); } cur_dscr_usr = get_dscr_usr(); if (cur_dscr_usr != dscr) { fprintf(stderr, "User DSCR should be %ld but " "is %ld\n", dscr, cur_dscr_usr); return 1; } } return 0; }
inline void randomPointTriangle(float a1, float a2, float a3, float b1, float b2, float b3, float c1, float c2, float c3, Eigen::Vector4f& p) { float r1 = static_cast<float> (uniform_deviate(rand())); float r2 = static_cast<float> (uniform_deviate(rand())); float r1sqr = sqrtf(r1); float OneMinR1Sqr = (1 - r1sqr); float OneMinR2 = (1 - r2); a1 *= OneMinR1Sqr; a2 *= OneMinR1Sqr; a3 *= OneMinR1Sqr; b1 *= OneMinR2; b2 *= OneMinR2; b3 *= OneMinR2; c1 = r1sqr * (r2 * c1 + b1) + a1; c2 = r1sqr * (r2 * c2 + b2) + a2; c3 = r1sqr * (r2 * c3 + b3) + a3; p[0] = c1; p[1] = c2; p[2] = c3; p[3] = 0; }
inline void randPSurface(vtkPolyData * polydata, std::vector<double> * cumulativeAreas, double totalArea, Eigen::Vector4f& p) { float r = static_cast<float> (uniform_deviate(rand()) * totalArea); std::vector<double>::iterator low = std::lower_bound(cumulativeAreas->begin(), cumulativeAreas->end(), r); vtkIdType el = vtkIdType(low - cumulativeAreas->begin()); double A[3], B[3], C[3]; vtkIdType npts = 0; vtkIdType *ptIds = NULL; polydata->GetCellPoints(el, npts, ptIds); polydata->GetPoint(ptIds[0], A); polydata->GetPoint(ptIds[1], B); polydata->GetPoint(ptIds[2], C); randomPointTriangle(float(A[0]), float(A[1]), float(A[2]), float(B[0]), float(B[1]), float(B[2]), float(C[0]), float(C[1]), float(C[2]), p); }
void fill_darr(double arr[], size_t length) { for(size_t i=0; i<length; ++i) arr[i] = uniform_deviate()*length; }