Bitmap bmp = new Bitmap(900, 900);
using (Graphics g = Graphics.FromImage(bmp))
{
for (int y = 0; y < 900; y++)
{
for (int x = 0; x < 900; x++)
{
g.DrawRectangle(new Pen(new Random().Next(2) == 0? Color.Black : Color.White), new Rectangle(x,y,1,1));
}
}
}
bmp.Save("tmp.bmp");The results were appalling - as you can see, there is a clearly defined pattern, not at all a desirable feature of allegedly "random" numbers. The articles I read all states that Windows by default uses a Linear Congruential Random Number Generator, with a relatively low period (I believe 32767? So max value of a signed short ^_^). Perhaps it's time to start using the Mersenne Twister for generating random numbers ye?
Edit: I am appalled by my thickness; it only dawned on me later that such a method of random generation relies on different seed values. With the tight loop I'm currently using, each new Random is initialized to the same seed value because of how close they are being created in time (apparently, this random function takes its seed value from the system clock), so that explains why many pixels in a row were the same color. This new realization prompted me to make a Random object outside of the loop and call Random.Next from a reference to that within a loop, leading to much more satisfactory results - seen here.