Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    1
    Thanks
    0
    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
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,688
    Thanks
    80
    Thanked 4,650 Times in 4,612 Posts
    ????

    Except for these variables
    Code:
    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).
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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