System.Random

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon Agiato

    System.Random

    Hello,
    I am sure this problem is easy to spot but I have been at this project all
    day and the frustration has finally overcome me. I am using this function
    in order to produce a standard normal distribution random number generator
    and then using the function in another part of my program in order to use
    the value. This function is called for many iterations. The problem is,
    through each run I am getting the exact same number generated from this
    function with the occasional slight variation. How can I make this function
    create numbers randomly? I am thinking since it is being run so fast the
    same seed is being used, but how can I change that? This is C# code, used
    in a web application. Here's the code:

    private double sndRNG()
    {
    const double quantityRN = 16.0;

    uint start = 0;
    double tmp = 0.0;
    Random randomNumber = new Random();
    for(; start != quantityRN; ++start)
    {
    tmp += Convert.ToDoubl e(randomNumber. Next(10));
    }

    double tmp2 = tmp / quantityRN;

    return (tmp2 - 4.5) * 4.0 / Math.Sqrt(8.25) ;
    }

    Thanks for any and all suggestions.

    --
    Jon Agiato
    Jon@agiato.net
    AOL IM: agiatojon



  • Cole Breidenbach

    #2
    System.Random

    Try using a seed value for the Random object constructor.
    This should create a pseudo-random result.

    Hope this helps.[color=blue]
    >-----Original Message-----
    >Hello,
    >I am sure this problem is easy to spot but I have been at[/color]
    this project all[color=blue]
    >day and the frustration has finally overcome me. I am[/color]
    using this function[color=blue]
    >in order to produce a standard normal distribution random[/color]
    number generator[color=blue]
    >and then using the function in another part of my program[/color]
    in order to use[color=blue]
    >the value. This function is called for many iterations.[/color]
    The problem is,[color=blue]
    >through each run I am getting the exact same number[/color]
    generated from this[color=blue]
    >function with the occasional slight variation. How can I[/color]
    make this function[color=blue]
    >create numbers randomly? I am thinking since it is being[/color]
    run so fast the[color=blue]
    >same seed is being used, but how can I change that? This[/color]
    is C# code, used[color=blue]
    >in a web application. Here's the code:
    >
    >private double sndRNG()
    >{
    > const double quantityRN = 16.0;
    >
    > uint start = 0;
    > double tmp = 0.0;
    > Random randomNumber = new Random();
    > for(; start != quantityRN; ++start)
    > {
    > tmp += Convert.ToDoubl e(randomNumber. Next(10));
    > }
    >
    > double tmp2 = tmp / quantityRN;
    >
    > return (tmp2 - 4.5) * 4.0 / Math.Sqrt(8.25) ;
    >}
    >
    >Thanks for any and all suggestions.
    >
    >--
    >Jon Agiato
    >Jon@agiato.n et
    >AOL IM: agiatojon
    >http://www.agiato.net
    >
    >
    >.
    >[/color]

    Comment

    • Peter Koen

      #3
      Re: System.Random

      "Jon Agiato" <JonAgiato@nyc. rr.com> wrote in
      news:Jwjlb.3696 $Gq.1327503@twi ster.nyc.rr.com :

      [...]

      The Random class takes some time value (afaik the currentticks) as seed.
      that may be not enough difference for your application.

      one easy to do thing would be to write your own pseudo-random function.

      this one should do nicely:

      public class Rand
      {
      private static int seed = 31337; //some value

      Public int NextInt()
      {
      seed= ( seed * 15625 + 1 ) & 32767;
      return seed;
      }
      }


      --
      best regards

      Peter Koen
      -----------------------------------
      MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS

      Comment

      • mikeb

        #4
        Re: System.Random

        Jon Agiato wrote:[color=blue]
        > Hello,
        > I am sure this problem is easy to spot but I have been at this project all
        > day and the frustration has finally overcome me. I am using this function
        > in order to produce a standard normal distribution random number generator
        > and then using the function in another part of my program in order to use
        > the value. This function is called for many iterations. The problem is,
        > through each run I am getting the exact same number generated from this
        > function with the occasional slight variation. How can I make this function
        > create numbers randomly? I am thinking since it is being run so fast the
        > same seed is being used, but how can I change that? This is C# code, used
        > in a web application. Here's the code:
        >
        > private double sndRNG()
        > {
        > const double quantityRN = 16.0;
        >
        > uint start = 0;
        > double tmp = 0.0;
        > Random randomNumber = new Random();
        > for(; start != quantityRN; ++start)
        > {
        > tmp += Convert.ToDoubl e(randomNumber. Next(10));
        > }
        >
        > double tmp2 = tmp / quantityRN;
        >
        > return (tmp2 - 4.5) * 4.0 / Math.Sqrt(8.25) ;
        > }
        >
        > Thanks for any and all suggestions.
        >[/color]

        You can seed the rng only once by making it a private member of your
        class rather than a local in your method:

        private Random randomNumber = new Random();

        private double sndRNG()
        {
        const double quantityRN = 16.0;

        uint start = 0;
        double tmp = 0.0;
        // Random randomNumber = new Random();
        for(; start != quantityRN; ++start)
        {
        tmp += Convert.ToDoubl e(randomNumber. Next(10));
        }

        double tmp2 = tmp / quantityRN;

        return (tmp2 - 4.5) * 4.0 / Math.Sqrt(8.25) ;
        }

        Now the generator is seeded only once - when your class is instantiated.

        --
        mikeb

        Comment

        • mikeb

          #5
          Re: System.Random

          Jon Agiato wrote:
          [color=blue]
          > Hello,
          > I am sure this problem is easy to spot but I have been at this project all
          > day and the frustration has finally overcome me. I am using this function
          > in order to produce a standard normal distribution random number generator
          > and then using the function in another part of my program in order to use
          > the value. This function is called for many iterations. The problem is,
          > through each run I am getting the exact same number generated from this
          > function with the occasional slight variation. How can I make this function
          > create numbers randomly? I am thinking since it is being run so fast the
          > same seed is being used, but how can I change that? This is C# code, used
          > in a web application. Here's the code:
          >
          > private double sndRNG()
          > {
          > const double quantityRN = 16.0;
          >
          > uint start = 0;
          > double tmp = 0.0;
          > Random randomNumber = new Random();
          > for(; start != quantityRN; ++start)
          > {
          > tmp += Convert.ToDoubl e(randomNumber. Next(10));
          > }
          >
          > double tmp2 = tmp / quantityRN;
          >
          > return (tmp2 - 4.5) * 4.0 / Math.Sqrt(8.25) ;
          > }
          >
          > Thanks for any and all suggestions.
          >[/color]


          Another comment that I forgot to include in my previous posting. I have
          seen evidence (but haven't looked very closely at the issue) that the
          Random class provides a *very* poor distribution. It's possible that
          this has been fixed in the Framework 1.1 - if it's really a problem at all.

          If your application really needs a decent distribution of random
          numbers, then you might want to look at the RNGCryptoServic eProvider
          class to get higher quality.

          --
          mikeb

          Comment

          • Richard A. Lowe

            #6
            Re: System.Random



            --
            Veuillez m'excuser, mon Français est très pauvre. Cependant, si vous voyez
            mauvais C #, c'est mon défaut!
            "mikeb" <mailbox.google @mailnull.com> wrote in message
            news:e1934uDmDH A.360@TK2MSFTNG P12.phx.gbl...[color=blue]
            > Jon Agiato wrote:
            >[color=green]
            > > Hello,
            > > I am sure this problem is easy to spot but I have been at this project[/color][/color]
            all[color=blue][color=green]
            > > day and the frustration has finally overcome me. I am using this[/color][/color]
            function[color=blue][color=green]
            > > in order to produce a standard normal distribution random number[/color][/color]
            generator[color=blue][color=green]
            > > and then using the function in another part of my program in order to[/color][/color]
            use[color=blue][color=green]
            > > the value. This function is called for many iterations. The problem[/color][/color]
            is,[color=blue][color=green]
            > > through each run I am getting the exact same number generated from this
            > > function with the occasional slight variation. How can I make this[/color][/color]
            function[color=blue][color=green]
            > > create numbers randomly? I am thinking since it is being run so fast[/color][/color]
            the[color=blue][color=green]
            > > same seed is being used, but how can I change that? This is C# code,[/color][/color]
            used[color=blue][color=green]
            > > in a web application. Here's the code:
            > >
            > > private double sndRNG()
            > > {
            > > const double quantityRN = 16.0;
            > >
            > > uint start = 0;
            > > double tmp = 0.0;
            > > Random randomNumber = new Random();
            > > for(; start != quantityRN; ++start)
            > > {
            > > tmp += Convert.ToDoubl e(randomNumber. Next(10));
            > > }
            > >
            > > double tmp2 = tmp / quantityRN;
            > >
            > > return (tmp2 - 4.5) * 4.0 / Math.Sqrt(8.25) ;
            > > }
            > >
            > > Thanks for any and all suggestions.
            > >[/color]
            >
            >
            > Another comment that I forgot to include in my previous posting. I have
            > seen evidence (but haven't looked very closely at the issue) that the
            > Random class provides a *very* poor distribution. It's possible that
            > this has been fixed in the Framework 1.1 - if it's really a problem at[/color]
            all.[color=blue]
            >
            > If your application really needs a decent distribution of random
            > numbers, then you might want to look at the RNGCryptoServic eProvider
            > class to get higher quality.
            >
            > --
            > mikeb
            >[/color]


            Comment

            • Bret Mulvey [MS]

              #7
              Re: System.Random

              "Jon Agiato" <JonAgiato@nyc. rr.com> wrote in message
              news:Jwjlb.3696 $Gq.1327503@twi ster.nyc.rr.com ...[color=blue]
              > Hello,
              > .... I am using this function
              > in order to produce a standard normal distribution random number generator
              > and then using the function in another part of my program in order to use
              > the value. This function is called for many iterations. The problem is,
              > through each run I am getting the exact same number generated from this
              > function with the occasional slight variation. How can I make this[/color]
              function[color=blue]
              > create numbers randomly?[/color]

              As others have mentioned, you'll want to create your System.Random object
              once and reuse it instead of recreating it for each function call.

              Adding 10 random values will generate an approximately normal distribution,
              but you can do this directly with just two random values, as follows:

              using System;

              class Normal
              {
              static Random rand = new Random();

              public static double sndRNG()
              {
              double x = rand.NextDouble ();
              double y = rand.NextDouble ();
              return Math.Sqrt(-2.0 * Math.Log(x)) * Math.Cos(Math.P i * y);
              }
              }

              class App
              {
              public static int Main()
              {
              Console.WriteLi ne(Normal.sndRN G());
              }
              }



              Comment

              • Jon Agiato

                #8
                Re: System.Random

                Thanks for all the suggestions, I tried all of them but I am still getting
                the same numbers each time. When the user presses the button I have it for
                testing so that I can see the values the application generated in a label.
                With one press, all of the numbers are the same. With successive presses we
                get different numbers, but not with the single press. Here is a larger
                chunk of code:

                static Random randomNumber = new Random();

                private double sndRNG()
                {
                const double QUANTITYRN = 16.0;

                uint start = 0;
                double tmp = 0.0;

                for(; start != QUANTITYRN; ++start)
                {
                tmp += Convert.ToDoubl e(randomNumber. Next(10));
                }

                double tmp2 = tmp / QUANTITYRN;

                return (tmp2 - 4.5) * 4.0 / Math.Sqrt(8.25) ;
                }

                private void runSimulation_C lick(object sender, System.EventArg s e)
                {
                double sampleSize = new double();
                try
                {
                if(Convert.ToDo uble(SampleSize .Text) > 0 &&
                Convert.ToDoubl e(SampleSize.Te xt) <= 30)
                {
                sampleSize = Convert.ToDoubl e(SampleSize.Te xt);
                }
                else
                {
                sizeRangeError. Text = "Valid range: (0, 30]";
                }
                }
                catch(System.Fo rmatException)
                {
                sizeRangeError. Text = "Valid range: (0, 30]";
                }

                double draws = new double();
                try
                {
                if(Convert.ToDo uble(Draws.Text ) > 0 && Convert.ToDoubl e(Draws.Text) <=
                100)
                {
                draws = Convert.ToDoubl e(Draws.Text);
                }
                else
                {
                drawRangeError. Text = "Valid range: (0, 100]";
                }
                }
                catch(System.Fo rmatException)
                {
                drawRangeError. Text = "Valid range: (0, 100]";
                }

                CInterval cInterval = new CInterval();
                ArrayList contIntervals = new ArrayList();

                uint start = 0;
                for(; start != draws; ++start)
                {
                double temp = 0.0;
                uint star = 0;
                for(; star != sampleSize; ++star)
                {
                temp += sndRNG();
                }

                double avgRN = temp / sampleSize;
                cInterval.setLo wer(avgRN - 1.96 / Math.Sqrt(sampl eSize));
                cInterval.setUp per(avgRN + 1.96 / Math.Sqrt(sampl eSize));

                const double ZERO = 0.0;
                if(cInterval.ge tLower() == ZERO || cInterval.getUp per() == ZERO)
                {
                cInterval.setVa lid(true);
                }
                else if(cInterval.ge tLower() < ZERO && cInterval.getUp per() > ZERO)
                {
                cInterval.setVa lid(true);
                }
                else
                {
                cInterval.setVa lid(false);
                }

                contIntervals.A dd(cInterval);
                }

                // calculate percentages, and update labels
                uint good = 0, bad = 0;
                foreach(CInterv al CI in contIntervals)
                {
                if(CI.getValid( ) == true)
                {
                ++good;
                }
                else if(CI.getValid( ) == false)
                {
                ++bad;
                }

                // for testing
                Label2.Text += CI.getLower() + ", " + CI.getUpper() + " ";
                }

                Label5.Text = good.ToString() ;
                Label7.Text = bad.ToString();
                }
                }

                Thanks again for any and all suggestions!

                --
                Jon Agiato
                Jon@agiato.net
                AOL IM: agiatojon

                "Bret Mulvey [MS]" <bretm@online.m icrosoft.com> wrote in message
                news:Pmnlb.8419 71$Ho3.252729@s ccrnsc03...[color=blue]
                > "Jon Agiato" <JonAgiato@nyc. rr.com> wrote in message
                > news:Jwjlb.3696 $Gq.1327503@twi ster.nyc.rr.com ...[color=green]
                > > Hello,
                > > .... I am using this function
                > > in order to produce a standard normal distribution random number[/color][/color]
                generator[color=blue][color=green]
                > > and then using the function in another part of my program in order to[/color][/color]
                use[color=blue][color=green]
                > > the value. This function is called for many iterations. The problem[/color][/color]
                is,[color=blue][color=green]
                > > through each run I am getting the exact same number generated from this
                > > function with the occasional slight variation. How can I make this[/color]
                > function[color=green]
                > > create numbers randomly?[/color]
                >
                > As others have mentioned, you'll want to create your System.Random object
                > once and reuse it instead of recreating it for each function call.
                >
                > Adding 10 random values will generate an approximately normal[/color]
                distribution,[color=blue]
                > but you can do this directly with just two random values, as follows:
                >
                > using System;
                >
                > class Normal
                > {
                > static Random rand = new Random();
                >
                > public static double sndRNG()
                > {
                > double x = rand.NextDouble ();
                > double y = rand.NextDouble ();
                > return Math.Sqrt(-2.0 * Math.Log(x)) * Math.Cos(Math.P i * y);
                > }
                > }
                >
                > class App
                > {
                > public static int Main()
                > {
                > Console.WriteLi ne(Normal.sndRN G());
                > }
                > }
                >
                >
                >[/color]


                Comment

                • news.microsoft.com

                  #9
                  Re: System.Random

                  Use System.Security namespace for random if you need good randomisation.


                  "Jon Agiato" <JonAgiato@nyc. rr.com> wrote in message
                  news:_Xxlb.8243 $ri.1817411@twi ster.nyc.rr.com ...[color=blue]
                  > Thanks for all the suggestions, I tried all of them but I am still getting
                  > the same numbers each time. When the user presses the button I have it[/color]
                  for[color=blue]
                  > testing so that I can see the values the application generated in a label.
                  > With one press, all of the numbers are the same. With successive presses[/color]
                  we[color=blue]
                  > get different numbers, but not with the single press. Here is a larger
                  > chunk of code:
                  >
                  > static Random randomNumber = new Random();
                  >
                  > private double sndRNG()
                  > {
                  > const double QUANTITYRN = 16.0;
                  >
                  > uint start = 0;
                  > double tmp = 0.0;
                  >
                  > for(; start != QUANTITYRN; ++start)
                  > {
                  > tmp += Convert.ToDoubl e(randomNumber. Next(10));
                  > }
                  >
                  > double tmp2 = tmp / QUANTITYRN;
                  >
                  > return (tmp2 - 4.5) * 4.0 / Math.Sqrt(8.25) ;
                  > }
                  >
                  > private void runSimulation_C lick(object sender, System.EventArg s e)
                  > {
                  > double sampleSize = new double();
                  > try
                  > {
                  > if(Convert.ToDo uble(SampleSize .Text) > 0 &&
                  > Convert.ToDoubl e(SampleSize.Te xt) <= 30)
                  > {
                  > sampleSize = Convert.ToDoubl e(SampleSize.Te xt);
                  > }
                  > else
                  > {
                  > sizeRangeError. Text = "Valid range: (0, 30]";
                  > }
                  > }
                  > catch(System.Fo rmatException)
                  > {
                  > sizeRangeError. Text = "Valid range: (0, 30]";
                  > }
                  >
                  > double draws = new double();
                  > try
                  > {
                  > if(Convert.ToDo uble(Draws.Text ) > 0 && Convert.ToDoubl e(Draws.Text) <=
                  > 100)
                  > {
                  > draws = Convert.ToDoubl e(Draws.Text);
                  > }
                  > else
                  > {
                  > drawRangeError. Text = "Valid range: (0, 100]";
                  > }
                  > }
                  > catch(System.Fo rmatException)
                  > {
                  > drawRangeError. Text = "Valid range: (0, 100]";
                  > }
                  >
                  > CInterval cInterval = new CInterval();
                  > ArrayList contIntervals = new ArrayList();
                  >
                  > uint start = 0;
                  > for(; start != draws; ++start)
                  > {
                  > double temp = 0.0;
                  > uint star = 0;
                  > for(; star != sampleSize; ++star)
                  > {
                  > temp += sndRNG();
                  > }
                  >
                  > double avgRN = temp / sampleSize;
                  > cInterval.setLo wer(avgRN - 1.96 / Math.Sqrt(sampl eSize));
                  > cInterval.setUp per(avgRN + 1.96 / Math.Sqrt(sampl eSize));
                  >
                  > const double ZERO = 0.0;
                  > if(cInterval.ge tLower() == ZERO || cInterval.getUp per() == ZERO)
                  > {
                  > cInterval.setVa lid(true);
                  > }
                  > else if(cInterval.ge tLower() < ZERO && cInterval.getUp per() > ZERO)
                  > {
                  > cInterval.setVa lid(true);
                  > }
                  > else
                  > {
                  > cInterval.setVa lid(false);
                  > }
                  >
                  > contIntervals.A dd(cInterval);
                  > }
                  >
                  > // calculate percentages, and update labels
                  > uint good = 0, bad = 0;
                  > foreach(CInterv al CI in contIntervals)
                  > {
                  > if(CI.getValid( ) == true)
                  > {
                  > ++good;
                  > }
                  > else if(CI.getValid( ) == false)
                  > {
                  > ++bad;
                  > }
                  >
                  > // for testing
                  > Label2.Text += CI.getLower() + ", " + CI.getUpper() + " ";
                  > }
                  >
                  > Label5.Text = good.ToString() ;
                  > Label7.Text = bad.ToString();
                  > }
                  > }
                  >
                  > Thanks again for any and all suggestions!
                  >
                  > --
                  > Jon Agiato
                  > Jon@agiato.net
                  > AOL IM: agiatojon
                  > http://www.agiato.net
                  > "Bret Mulvey [MS]" <bretm@online.m icrosoft.com> wrote in message
                  > news:Pmnlb.8419 71$Ho3.252729@s ccrnsc03...[color=green]
                  > > "Jon Agiato" <JonAgiato@nyc. rr.com> wrote in message
                  > > news:Jwjlb.3696 $Gq.1327503@twi ster.nyc.rr.com ...[color=darkred]
                  > > > Hello,
                  > > > .... I am using this function
                  > > > in order to produce a standard normal distribution random number[/color][/color]
                  > generator[color=green][color=darkred]
                  > > > and then using the function in another part of my program in order to[/color][/color]
                  > use[color=green][color=darkred]
                  > > > the value. This function is called for many iterations. The problem[/color][/color]
                  > is,[color=green][color=darkred]
                  > > > through each run I am getting the exact same number generated from[/color][/color][/color]
                  this[color=blue][color=green][color=darkred]
                  > > > function with the occasional slight variation. How can I make this[/color]
                  > > function[color=darkred]
                  > > > create numbers randomly?[/color]
                  > >
                  > > As others have mentioned, you'll want to create your System.Random[/color][/color]
                  object[color=blue][color=green]
                  > > once and reuse it instead of recreating it for each function call.
                  > >
                  > > Adding 10 random values will generate an approximately normal[/color]
                  > distribution,[color=green]
                  > > but you can do this directly with just two random values, as follows:
                  > >
                  > > using System;
                  > >
                  > > class Normal
                  > > {
                  > > static Random rand = new Random();
                  > >
                  > > public static double sndRNG()
                  > > {
                  > > double x = rand.NextDouble ();
                  > > double y = rand.NextDouble ();
                  > > return Math.Sqrt(-2.0 * Math.Log(x)) * Math.Cos(Math.P i * y);
                  > > }
                  > > }
                  > >
                  > > class App
                  > > {
                  > > public static int Main()
                  > > {
                  > > Console.WriteLi ne(Normal.sndRN G());
                  > > }
                  > > }
                  > >
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • mikeb

                    #10
                    Re: System.Random

                    Jon Agiato wrote:
                    [color=blue]
                    > Thanks for all the suggestions, I tried all of them but I am still getting
                    > the same numbers each time. When the user presses the button I have it for
                    > testing so that I can see the values the application generated in a label.
                    > With one press, all of the numbers are the same. With successive presses we
                    > get different numbers, but not with the single press. Here is a larger
                    > chunk of code:
                    >[/color]

                    .... code snipped ...

                    I tried your code here, and I'm not seeing 'the same numbers each time',
                    but then I'm not sure exactly what I'm supposed to look at, and I had to
                    fill in a bit of code to get your sample to compile (making assumptions
                    along the way).

                    I suggest you post a small, complete *console* application that someone
                    can just compile at the command line (or paste in one shot into VS.NET)
                    that shows the problem you're running into now.

                    I'd point you to Jon Skeet's page about samples to repro problems, but
                    his site seems to be unavailable at the moment.

                    --
                    mikeb

                    Comment

                    • Jon Skeet [C# MVP]

                      #11
                      Re: System.Random

                      mikeb <mailbox.google @mailnull.com> wrote:[color=blue]
                      > I suggest you post a small, complete *console* application that someone
                      > can just compile at the command line (or paste in one shot into VS.NET)
                      > that shows the problem you're running into now.[/color]

                      Hear hear :)
                      [color=blue]
                      > I'd point you to Jon Skeet's page about samples to repro problems, but
                      > his site seems to be unavailable at the moment.[/color]

                      Mmm, it does, doesn't it? Then again, I can't get to Slashdot either...

                      Anyway, when it's back up, it's at

                      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.


                      Until that time, here's the google cache of it:


                      --
                      Jon Skeet - <skeet@pobox.co m>
                      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                      If replying to the group, please do not mail me too

                      Comment

                      • Jon Agiato

                        #12
                        Re: System.Random

                        Hi guys,
                        Thanks for the suggestions. It turns out the problem was something really
                        silly in another part of the program. I posted that stuff after a long
                        period spent with the computer, sometimes it's just best to leave it alone
                        for a bit and come back to it. In any case, everythings fixed and thanks
                        again for the suggestions.

                        --
                        Jon Agiato
                        Jon@agiato.net
                        AOL IM: agiatojon

                        "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
                        news:MPG.1a00cd 9fa7474d9c9898f 9@msnews.micros oft.com...[color=blue]
                        > mikeb <mailbox.google @mailnull.com> wrote:[color=green]
                        > > I suggest you post a small, complete *console* application that someone
                        > > can just compile at the command line (or paste in one shot into VS.NET)
                        > > that shows the problem you're running into now.[/color]
                        >
                        > Hear hear :)
                        >[color=green]
                        > > I'd point you to Jon Skeet's page about samples to repro problems, but
                        > > his site seems to be unavailable at the moment.[/color]
                        >
                        > Mmm, it does, doesn't it? Then again, I can't get to Slashdot either...
                        >
                        > Anyway, when it's back up, it's at
                        >
                        > http://www.pobox.com/~skeet/csharp/complete.html
                        >
                        > Until that time, here's the google cache of it:
                        > http://tinyurl.com/rx28
                        >
                        > --
                        > Jon Skeet - <skeet@pobox.co m>
                        > http://www.pobox.com/~skeet
                        > If replying to the group, please do not mail me too[/color]


                        Comment

                        • mikeb

                          #13
                          Re: System.Random

                          Jon Agiato wrote:[color=blue]
                          > ... sometimes it's just best to leave it alone for a bit and come back to it...[/color]

                          I know what you mean! Glad it's all sorted out.

                          --
                          mikeb

                          Comment

                          • Bret Mulvey [MS]

                            #14
                            Re: System.Random


                            "Jon Agiato" <JonAgiato@nyc. rr.com> wrote in message
                            news:gQTlb.2952 3$pT1.14711@twi ster.nyc.rr.com ...[color=blue]
                            > Hi guys,
                            > Thanks for the suggestions. It turns out the problem was something really
                            > silly in another part of the program. I posted that stuff after a long
                            > period spent with the computer, sometimes it's just best to leave it alone
                            > for a bit and come back to it. In any case, everythings fixed and thanks
                            > again for the suggestions.
                            >[/color]

                            You might try the method below. It's considerably faster (only 2 calls to
                            System.Random instead of 16) but still returns Gaussian normal results.

                            double Normal()
                            {
                            return Math.Sqrt(-2.0 * Math.Log(rand.N extDouble())) * Math.Cos(Math.P I
                            * rand.NextDouble ());
                            }


                            Comment

                            Working...