Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2014
    Thanked 0 Times in 0 Posts

    Knuth's subtractive random number generator. Which variables can be changed?

    I have Knuth's subtractive random number generator code taken from this site: Subtractive generator - Rosetta Code

    My question is:

    What are the manipulating variables and what are the costants?

    Are all the numbers in this code variables?

  2. #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,945 Times in 4,906 Posts

    Except for these variables
    int state[55], si = 0, sj = 0;
    all named variables are just local variables. So the names don't matter to any code outside of each function; change them as you wish. All the numbers given in there are constants. Don't touch them. Could you instead declare them (esp. in C++ or C# or Java) as constants, assigning them names? Sure.

    Remember that int main() is just code to demonstrate how to use the two functions. You can throw it away and incorporate the other code in you C or C++ code (though it would be better to rewrite this a class in C++, of course).
    Be yourself. No one else is as qualified.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts