Loading ...
Sorry, an error occurred while loading the content.

Portable Random Seed

Expand Messages
  • Jason Rennie
    Hi all, I m currently writing a pseudo random number generator for a program i m working on. I tired the default ones that come with small eiffel, but the
    Message 1 of 5 , Aug 2, 1999
    • 0 Attachment
      Hi all,

      I'm currently writing a pseudo random number generator for a program i'm
      working on. I tired the default ones that come with small eiffel, but the
      method for randomly seeding the generator is useless (at least on my linux
      box), as it kept giving me the same number.

      I'm hopinh to extend teh class to add a few differnt prng's and the like, but
      at the moment i'm having trouble finding a portable random source of bits for
      the seed. Any ideas ??

      I currently am using variuos /proc/ files on the linux box and this could never
      hope to be ported to windows, so i need to find another way to get a seed ??

      I was thinking finding some way to use the HDD timings or something but i'm not
      sure how to go about getting the information. Any ideas at all about a portable
      (or at least easily worked around) ideas would be most appreciated.

      Jason
      --
      "Black Holes are where God divided by zero !"
    • Friedrich Dominicus
      Is that something you can use: my_random.c #include #include static time_t now; int c_rand(void){ return rand(); } void c_srand (unsigned
      Message 2 of 5 , Aug 2, 1999
      • 0 Attachment
        Is that something you can use:
        my_random.c

        #include <stdlib.h>
        #include <time.h>

        static time_t now;

        int c_rand(void){
        return rand();
        }

        void c_srand (unsigned int seed){
        srand(seed);
        }

        void c_set_random_seed (void){
        now = time(NULL);
        c_srand(now);
        }

        int c_get_random_time_seed(void){
        return (int) now;
        }



        my_random.e
        feature
        last_random: INTEGER;

        next_random is
        do
        last_random := c_rand;
        end;

        set_seed (new_seed: INTEGER) is
        do
        c_srand(new_seed);
        end;

        set_random_seed is
        do
        c_set_random_seed;
        end;

        get_random_seed: INTEGER is
        do
        Result := c_get_random_time_seed;
        end;

        feature{NONE}

        c_rand : INTEGER is
        external "C"
        end;

        c_srand (seed: INTEGER) is
        external "C"
        end;

        c_set_random_seed is
        external "C"
        end;

        c_get_random_time_seed: INTEGER is
        external "C"
        end;


        end

        c_set_random seed take the time since 1.1.1970 00:00:00 AFAIK so might
        be somewhat randomly.

        Hope this helps a bit
        Regards
        Friedrich
      • David Broadfoot
        Hi Jason, Loryn Jenkins posted one recently on comp.lang.eiffel -- you could use it as a basis for a portable seeder. It is basically = (pid * time * date).abs
        Message 3 of 5 , Aug 2, 1999
        • 0 Attachment
          Hi Jason,

          Loryn Jenkins posted one recently on comp.lang.eiffel -- you could use it as a
          basis for a portable seeder. It is basically = (pid * time * date).abs

          http://x43.deja.com/%5bST_rn=md]/getdoc.xp?AN=493070665&CONTEXT=933605188.17981768
          04&hitnum=7

          Regards,
          David

          ------------------------------------------------------------------------
          David Broadfoot Email: david@...
          Synax Systems Pty Ltd Phone: +61 2 9905 5977
          2/16 Ada Avenue, Brookvale Mobile: +61 417 788 488
          Sydney NSW 2100 Australia Fax: +61 2 9905 5922
          ------------------------------------------------------------------------


          > -----Original Message-----
          > From: Jason Rennie [mailto:jwrennie@...]
          > Sent: Monday, 2 August 1999 23:22
          > To: SmallEiffel@...
          > Subject: Portable Random Seed
          >
          >
          > Hi all,
          >
          > I'm currently writing a pseudo random number generator for a program i'm
          > working on. I tired the default ones that come with small eiffel, but the
          > method for randomly seeding the generator is useless (at least on my linux
          > box), as it kept giving me the same number.
          >
          > I'm hopinh to extend teh class to add a few differnt prng's and the like, but
          > at the moment i'm having trouble finding a portable random source of bits for
          > the seed. Any ideas ??
          >
          > I currently am using variuos /proc/ files on the linux box and this
          > could never
          > hope to be ported to windows, so i need to find another way to get a seed ??
          >
          > I was thinking finding some way to use the HDD timings or something
          > but i'm not
          > sure how to go about getting the information. Any ideas at all about
          > a portable
          > (or at least easily worked around) ideas would be most appreciated.
          >
          > Jason
          > --
          > "Black Holes are where God divided by zero !"
          >
          >
        • James Graves
          ... You should probably check out the source code for PGP, it is supposed to have a very good PRNG. Since PGP runs on Windows and Unix, I assume the code is
          Message 4 of 5 , Aug 2, 1999
          • 0 Attachment
            On Mon, 2 Aug 1999, Jason Rennie wrote:

            > I currently am using variuos /proc/ files on the linux box and this could never
            > hope to be ported to windows, so i need to find another way to get a seed ??
            >
            > I was thinking finding some way to use the HDD timings or something but i'm not
            > sure how to go about getting the information. Any ideas at all about a portable
            > (or at least easily worked around) ideas would be most appreciated.

            You should probably check out the source code for PGP, it is supposed to
            have a very good PRNG. Since PGP runs on Windows and Unix, I assume the
            code is portable, but I haven't looked at it myself. The source is at:

            http://www.pgpi.org

            James Graves

            _______________________________________________________________________________
            http://www.xnet.com/~ansible Applying to be Dr. Utonium's lab assistant.
          • Joachim Durchholz
            ... Nothing portable is available. The best you can do is trying various sources of hopefully random bits and distilling your seed from there. Take a look at
            Message 5 of 5 , Aug 10, 1999
            • 0 Attachment
              Jason Rennie wrote:
              >
              > [...] at the moment i'm having trouble finding a portable random
              > source of bits for the seed. Any ideas ??

              Nothing portable is available. The best you can do is trying various
              sources of hopefully random bits and distilling your seed from there.

              Take a look at Bruce Schneier's Applied Cryptography for details.

              Regards,
              Joachim
              --
              Please don't send unsolicited advertisements.
            Your message has been successfully submitted and would be delivered to recipients shortly.