Menu

command line/gsl

omsoq
2008-06-24
2012-09-26
  • omsoq

    omsoq - 2008-06-24

    Hi, I'm trying to use GSL random number generators to supply numbers for my program. I can run the basic programs fine, but in order to change the generator or give it a different seed it says to do things on the command line. Can you do that with Dev-C++? I've never actually used a command-prompt window before and I'm really confused.

    This is where I'm looking:
    http://www.gnu.org/software/gsl/manual/html_node/Random-number-environment-variables.html

    If you could tell me how to go about providing a different seed, like they do at the bottom of the page, it would be much appreciated. (Whether you can do it directly from the Dev-C++ main screen or another way.)

    Thank you.

     
    • cpns

      cpns - 2008-06-24

      That page refers to Linux shell commands.

      It is merely setting environment variables. In windows you can run a command shell via Start->Run... enter cmd in the command box and click OK.

      To set the environment variables enter the following in the command shell:

      set GSL_RNG_TYPE="taus"
      set GSL_RNG_SEED=123

      Then run your program. The environment applies only to this command shell session, you you have to run your program within this shell as well.

      I seem to remember there is a project setting dialog that allows environment variables to be set when a program is executed by the IDE, but I do not have Dev-C++ installed here so I can't tell you for sure.

      However I don't think this is particularly useful or convenient. I believe that you are misreading this documentation. It does not say that you have to do that to set the seed, it merely says that you can do it that way. You can do it directly in your code through the gsl_rng_set() function: http://www.gnu.org/software/gsl/manual/html_node/Random-number-generator-initialization.html

      The only purpose of using the environment variables is that it gives you external control of which algorithm and seed are used without having to modify the code. This may be useful for testing or analysing the quality of various generators, but may not be what you need.

      Clifford

       
    • omsoq

      omsoq - 2008-06-24

      Okay, I would rather do it through gsl_rng_set, I just couldn't get it to work before. :( I guess I'm not sure how it's supposed to be used. Can you tell me what the notation would be for changing the seed? I'm pretty confused...
      Thanks for your answer.

       
    • cpns

      cpns - 2008-06-26

      If the your preferred method did not work, you would have been better of explaining what you did and how it went wrong and gotten an answer to that. You should post your code and the build log.

      However, determined purely from the documentation (since I have never used it, and have not installed it)...

      // pointer to the selected generator
      gsl_rng *random_generator ;

      // a random seed - use what you like
      // here the return value of time() or clock()
      // is popular for unpredictability
      unsigned long seed = 123 ;

      // recipient of the random number
      unsigned long random_number ;

      // instantiate the generator (one of many possible generators - see below)
      random_generator = gsl_rng_alloc( gsl_rng_taus ) ;

      // seed the generator
      gsl_rng_set( random_generator, seed ) ;

      // get a random number integer
      random_number = gsl_rng_get( random_generator ) ;

      // Then when you are all done delete the generator
      gsl_rng_free( random_generator ) ;

      The possible values for the generator parameter of gsl_rng_alloc() are listed here: http://www.gnu.org/software/gsl/manual/html_node/Random-number-generator-algorithms.html , here: http://www.gnu.org/software/gsl/manual/html_node/Unix-random-number-generators.html , and here: http://www.gnu.org/software/gsl/manual/html_node/Other-random-number-generators.html . Information on generator performance to assist in selecting an appropriate balance of speed and randomness for your application is provided here: http://www.gnu.org/software/gsl/manual/html_node/Random-Number-Generator-Performance.html

      Being able to read and understand documentation is going to get you further faster, so I hope these hints help.

      I am pretty sure I was wrong about Dev-C++ supporting the setting of environment variables. If you want to use the environment variables method, and want to set environment variables in Windows to apply to all sessions rather than just the current command line session, then, set them in Control Panel->System->Advanced->Environment Variables.

      If you want to learn mode about the Windows command line then try: http://commandwindows.com/

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.