/* testrand.cxx */ /* Created by Laurence D. Finston (LDF) Di 6. Jun 14:09:09 CEST 2023 */ /* (1) Copyright and License. */ /* Copyright (C) 2023 Laurence Finston */ /* This file is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 3 of the License, or */ /* (at your option) any later version. */ /* This file is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU General Public License for more details. */ /* You should have received a copy of the GNU General Public License */ /* along with GNU 3DLDF; if not, write to the Free Software */ /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* The author can be contacted at: */ /* Laurence D. Finston */ /* Laurence.Finston@gmx.de */ #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* * (1) main */ int main(int argc, char *argv[]) { /* ** (2) */ int x_shift_limit = 9; int y_shift_limit = 4; int loop_limit = 40; bool do_forty_fives = true; bool reflected_flag = false; char c = 0; long L = 0L; long x_shift_val = 0L; long y_shift_val = 0L; long x_shift_sign = 0L; long y_shift_sign = 0L; long rotation_val = 0L; stringstream temp_strm; ofstream out_strm; out_strm.open("sub_testrand.tex"); out_strm << "%% sub_testrand.tex" << endl << endl; time_t time_val = time(0); cout << "time_val == " << time_val << endl; srandom((long) time_val); /* Use |time_val| for seed. */ /* ** (2) */ for (int i = 0; i < loop_limit; ++i) { /* *** (3) |rotation_val| */ cout << "i == " << i << endl; L =random(); printf("L == %ld\n", L); if (do_forty_fives) /* Currently, should always be true. */ { rotation_val = (L % 8) * 45; } cout << "rotation_val == " << rotation_val << endl; /* *** (3) |reflected_flag| */ L = random(); printf("L == %ld\n", L); reflected_flag = static_cast(L % 2); cout << "reflected_flag == " << reflected_flag << endl; /* *** (3) |x_shift_sign| */ L = random(); printf("L == %ld\n", L); x_shift_sign = (L % 2) ? 1 : -1; cout << "x_shift_sign == " << x_shift_sign << endl; /* *** (3) |x_shift_val| */ L = random(); printf("L == %ld\n", L); x_shift_val = L % ((x_shift_limit) * 10000 + 1000); cout << "x_shift_val == " << x_shift_val << endl; float x_shift_val_f = x_shift_val; x_shift_val_f /= 10000; cout << "Before calling `fminf': x_shift_val_f == " << x_shift_val_f << endl; x_shift_val_f = fminf(x_shift_val_f, static_cast(x_shift_limit)); cout << "After calling `fminf': x_shift_val_f == " << x_shift_val_f << endl; x_shift_val_f *= x_shift_sign; cout << "After setting sign: x_shift_val_f == " << x_shift_val_f << endl; /* *** (3) */ /* *** (3) |y_shift_sign| */ L = random(); printf("L == %ld\n", L); y_shift_sign = (L % 2) ? 1 : -1; cout << "y_shift_sign == " << y_shift_sign << endl; /* *** (3) |y_shift_val| */ L = random(); printf("L == %ld\n", L); y_shift_val = L % ((y_shift_limit) * 10000 + 1000); cout << "y_shift_val == " << y_shift_val << endl; float y_shift_val_f = y_shift_val; y_shift_val_f /= 10000; cout << "Before calling `fminf': y_shift_val_f == " << y_shift_val_f << endl; y_shift_val_f = fminf(y_shift_val_f, static_cast(y_shift_limit)); cout << "After calling `fminf': y_shift_val_f == " << y_shift_val_f << endl; y_shift_val_f *= y_shift_sign; cout << "After setting sign: y_shift_val_f == " << y_shift_val_f << endl; /* *** (3) */ out_strm << "\\A{" << y_shift_val_f << "cm}" << "{" << x_shift_val_f << "cm}{ladybug3_rotated_" << setfill ('0') << setw (3) << rotation_val; if (reflected_flag) out_strm << "_reflected"; out_strm << ".eps}{" << setfill ('0') << setw (4) << (i+1) << "}" << endl << endl; /* *** (3) */ } /* ** (2) */ out_strm << "\\endinput" << endl << endl; out_strm.close(); return 0; } /* Local Variables: */ /* mode:CWEB */ /* End: */