Eric Kepes' crummy little weblog RSS 2.0
 Monday, February 18, 2008

So, you want to get some random numbers, and you want them to have a normal distribution (aka Gaussian or Bell Curve). You discover that the .Net Random class returns evenly distributed numbers (so given a range from 0-99, you are just as likely to get 0 as 50 or 99). What do you do?

Turns out, there is this thing called the Central Limit Theorem, that, in a somewhat complicated math fashion I probably understand if I go back and remember what I learned in High School math. Anyway, basically, what you need to do is take several samples, add them together, and then divide by the number of samples, and you get a fairly decent approximation of "normal".

Running the following sample in SnippetCompiler, and using Excel to make some histograms (which takes WAY longer than it should, btw), we can see how the number of samples affects the distribution. I used 1, 2, 3, and 5 samples per value, and obviously 1 has no "normality", 2 doesn't really, either. 3 is pretty good, 5 is better. For my purposes, I'll probably generally use 3.

   

  

1

2

3

5

10

110

33

6

0

20

82

64

30

7

30

105

110

94

66

40

93

137

161

174

50

92

197

239

277

60

95

162

229

277

70

109

141

162

137

80

117

92

57

56

90

104

48

20

6

100

93

16

2

0

private static Random _NumberGenerator = new Random();

    public static Random NumberGenerator
    {
        get { return _NumberGenerator; }
    }

    public static int GetNextGaussian(int minimum, int maximum, int precision)
    {
        int value = 0;
        for (int i = 0; i < precision; i++)
        {
            value += _NumberGenerator.Next(minimum, maximum);
        }

        return value / precision;
    }

public static void Main()
{
    try
    {
        using (StreamWriter writer = new StreamWriter("numbers.txt"))
        {
            for (int i = 0; i<1000; i++)
            {
                writer.WriteLine("{0},{1},{2},{3}",
                    GetNextGaussian(0, 100, 1),
                    GetNextGaussian(0, 100, 2),
                    GetNextGaussian(0, 100, 3),
                    GetNextGaussian(0, 100, 5));
            }
        }
    }
    catch (Exception ex)
    {
        WL(ex);
    }

    WL("");
    WL("Done.");

    RL();
}
Monday, February 18, 2008 8:55:41 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Code Snippets
 Sunday, February 17, 2008

Real World Software Configuration Management is a decent introduction to the world of Software Configuration Management (SCM). It is a fairly light read (took me a weekend in between plays while watching college and pro football). Part of the reason for the light read is that is doesn't go into a lot of detail about anything you probably don't know, and does go into painstaking detail about build details you probably have seen before.

If you are looking for a lot of detail about how to manage Source Control for a complicated product development, or other large project, it probably isn't a very good book for you. I was looking for detail about how to best handling branching and promotion states, which are two topics it hardly mentions. It also dwells on CVS and VSS, which are now fairly obsolete source control systems. On the other hand, it does provide a pretty good introduction about SCM in general, and things that you should know about. Given that Amazon is now selling it for $10, its probably a good deal, if you need a good introductory tome about SCM. If you want more detail, go elsewhere.

Sunday, February 17, 2008 7:24:49 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Reviews
 Thursday, January 03, 2008

So, there will be another one, and there is a date - April 12, 2008, same place as last year. Wanna present something? Let me know - its possible I may be being referred to here.

I should point out that I'm just a helper on the planning committee - the heavy lifting is being done by Dave Hoerster, Craig Oaks (who don't have blogs), Greg Akin, and Jared Roberts at the Pgh Tech Council.

Thursday, January 03, 2008 9:22:53 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
News | UserGroups
 Thursday, February 15, 2007

All of the SysInternals tools (except for some "toys") have been released as one big suite. Get it now!

Thursday, February 15, 2007 10:17:08 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
News
 Thursday, January 11, 2007

Saturday, April 14, 2007 - we're doing it again.

If you think you might want to get up in front of people interested in the things you are passionate about, this is your chance. The speaker slate is wide open right now. This is your chance to tell the world (or at least the Pittsburgh .Net community) about your favorite tool or project!

If you're not interested in speaking, but wish to attend - watch that site or this space - registration will be opening soon.

Thursday, January 11, 2007 8:42:05 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
News | UserGroups
 Wednesday, November 08, 2006

I had no idea you could do it, but I figured I'd give it a try and see what happens. Turns out, you can have a property with mixed accessibility, so you can allow public "getting", but only private "setting". This comes in handy when there is a value you want to wrap in a lock - I like to wrap items that may be accessed from multiple threads in a property, and control the locking there, to help ensure that I am always locking the same way.

Here's how you have mixed accessibility:

public bool IsRunning
{
   get
   {
      lock (_Lock)
      {
         return _IsRunning;
      }
   }
   private set
   {
      lock (_Lock)
      {
         _IsRunning = value;
      }
   }
}

One thing to note, you have to go from more "public" to less. This won't work:

private bool IsRunning
{
   public get
   {
      lock (_Lock)
      {
         return _IsRunning;
      }
   }
   set
   {
      lock (_Lock)
      {
         _IsRunning = value;
      }
   }
}

Wednesday, November 08, 2006 10:23:01 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Code Snippets
 Wednesday, October 18, 2006

So, anyway, I just got nailed with several hundred (approaching 1000) trackback spams. Cleanup was fun - at first, I tried to do it through the web UI, but that quickly induces carpal tunnel.

So, the next course of action, which you might have noticed, was to upgrade to dasBlog 1.9. Then, while I was waiting for the old version to ftp back to me (always backup first, right? :)), I went through the content and remove the trackbacks with a good old text editor - much quicker...

I think I got everything back up, and didn't screw up to much, but anyway - if you see anything strange, let me know. Since I made the switch, I haven't gotten any trackback spam, but I don't know if it's just because they had already abused me and moved on, or if dasBlog 1.9 really works to prevent trackback spam.

Wednesday, October 18, 2006 7:13:31 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Administrivia
 Sunday, October 15, 2006

OK, it's not really new, I'm still sitting in the same desk, but now I actually work for the client. As of October 1, I am an employee of McKesson Automation. It's a decent company (less screwed up than most any other larger company in Pittsburgh), and close to home, so when they approached me to roll over to full-time, I agreed.

This actually gives me more freedom than I had as a consultant to do some projects I had been hoping to work on, so maybe I might even blog more. Yeah, right... :)

Sunday, October 15, 2006 8:13:42 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Administrivia | News
Navigation
Archive
<February 2008>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
2425262728291
2345678
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2009
Eric W. Kepes
Sign In
Statistics
Total Posts: 100
This Year: 0
This Month: 0
This Week: 0
Comments: 12
Themes
All Content © 2009, Eric W. Kepes
DasBlog theme 'Business' created by Christoph De Baene (delarou)