# include # include # include # include # using namespace std; # # include "middle_square.hpp" # //****************************************************************************80 long long int middle_square_next ( long long int s, long long int d ) //****************************************************************************80 // // Purpose: // // middle_square_next() computes the next middle square random value. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 16 September 2022 // // Author: // // John Burkardt // // Reference: // // Brian Hayes, // The Middle of the Square, // 08 August 2022, // http://bit-player.org/ // // Input: // // long long int s: the current seed, of no more than 2*D digits. // // long long int d: HALF the number of digits. // Typical values are 2, 3, or 4. // // Output: // // long long int middle_square, the next seed. // { long long int divisor; long long int r; long long ten = 10; // // Square. // r = s * s; // // Drop last two digits. // divisor = ( long long int ) ( pow ( ten, d ) ); r = ( r / divisor ); // // Drop all but last four digits. // divisor = ( long long int ) ( pow ( ten, 2 * d ) ); r = ( r % divisor ); return r; }