Not Your Normal Random

Illustration

When I test with random data I usually tend to use normal distribution. This particular time I didn’t want that. I wanted to simulate sensor readings and that means that I cannot have values going around all willy-nilly. I wanted sensors to read their default value most of time with occasional trips to edge areas. This is code I ended up with:

private static double GetAbnormalRandom() {
    double rnd = Rnd.NextDouble();
    double xh = 0.5 - rnd;
    double xs = xh * xh * 2;
    double x = 0.5 + Math.Sign(xh) * xs;
    if (x < 1) { return x; } else { return 0.5; }
}

2) This is just standard random number. Minimum value is 0 and maximum is LOWER than 1 (it can also be written as [0,1)).

3) I than moved this number to minimum of -0.5 and maximum lower than 0.5 ([-0.5,0.5)).

4) In order to maximize our mean value, I decided upon square function. It gives us number ranging from 0 to less than 0.5 (0.52 gives 0.25 and multiplication by 2 moves this back to 0.5).

5) Everything could stop here sine I have my distribution already available in step 4. However, I wanted to get everything back into [0,1) range. It is just matter of adding 0.5 to whatever number we got in step 4. Sign operation is here to ensure that half of numbers go to less than 0.5 and half of them go above.

6) Of course all this math is causing rounding to our floating point numbers. In rare occasions that can cause our step 4 to generate positive range number that is equal to 0.5. It is very rare (approximately 1 in 1000000) and we can just add it in middle.

And this is it. Function will most probably return values around 0.5 with sharp drop in probability for values further toward edge (see graph).

For full code alongside some statistics you can download source code.

Microsoft Mathematics

Illustration

Last few years I hold position of self-proclaimed Microsoft expert. I am so used to people approaching me with various questions regarding Microsoft technology and products and people got used to me having an answer to anything Microsoft. I thought that I knew every Microsoft product there is. However, I had no idea about Microsoft Mathematics. Product has been available from 2006 and I got first whim of it just few hours ago.

Simplest description of it would be graphing calculator (like e.g. HP 49g) but it wouldn’t do justice to it since it only holds until you switch it to “Ink” input mode.

Ink mode is something wet dreams are made of. Not only that it recognizes letters but it also knows how to interpret fractions, exponents, greekish :) symbols and all other “math thingies”. I got so used to write one thing on computer and completely another on paper that I am now freaking at something that should be normal thing - properly formated equations. While Ink mode works with mouse, with tablet computer it is pure math porn.

And it doesn’t stop there. It also offers equation solving, bunch of common formulas with nice interface to enter all data, and very pretty graph controls. Everything is packed in simple and skinnable interface (albeit without Hello Kitty skin ;)). As long as you are not doing math for living, this program probably has everything you need.

I am not in my student days anymore so there is very little chance that I will use this program much. There is very limited need for math in business software. But this program made my eyes shine.

Download is available FOR FREE.

WinDays 11

Illustration

This WinDays in Rovinj, on 6th April 2011 at 9:00 I will give presentation named “Azure Java”.

It will be (hopefully) interesting talk about Microsoft Azure and Sun Oracle Java. After presentation there might be some beer involved so be sure to visit. :)

VHD Attach 2.00

Illustration

It took me a while but new version of VHD Attach is here. Although there isn’t much changed on surface, internals went through significant changes and quite a few bug-fixes.

Probably most visible change is adding auto-mount button directly on toolbar. It seems that lot of people were unaware of feature because it was buried in Options dialog.

Version is available at https://www.medo64.com/vhdattach/. Enjoy.

MagiWOL 3.00 (Beta 1)

Illustration

Although MagiWOL is not program that gets downloaded the most from these pages, it is definitely one that generates most of feedback. Good feedback from loyal users forced me to continue development and it is directly responsible for this beta.

Changes are:

  • No registry writes will be performed if application is not installed.
  • Double-click now wakes computer instead of editing entry.
  • Broadcast address now can be host name (useful for waking over Internet).
  • Lot of bug fixing.

Beta is available for download at https://www.medo64.com/magiwol/beta/.