4 added 1 character in body
source | link

C#, 369 288288 287 bytes

namespace System.Drawing{class P{static void Main(){var g=Graphics.FromHwnd((IntPtr)0);var r=new Random();var w=Windows.Forms.Screen.GetBounds(Point.Empty);for(var r=new Random();;)g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256),r.Next(256),r.Next(256))),r.Next(w.Width),r.Next(w.Height),1,1);}}}
namespace System.Drawing
{
    class P
    {
        static void Main()
        {
            var g = Graphics.FromHdc((IntPtr)0);
            var r = new Random();
            var w = Windows.Forms.Screen.GetBounds(Point.Empty);

            for (var r = new Random();;)
                g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256), r.Next(256), r.Next(256))),
                                r.Next(w.Width), r.Next(w.Height), 1, 1);
        }
    }
}

A version for 308 227227 226 bytes that only draws on the region 0-40:

namespace System.Drawing{class P{static void Main(){var g=Graphics.FromHdc((IntPtr)0);var;for(var r=new Random();for(;;)g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256),r.Next(256),r.Next(256))),r.Next(40),r.Next(40),1,1);}}}

C#, 369 288 bytes

namespace System.Drawing{class P{static void Main(){var g=Graphics.FromHwnd((IntPtr)0);var r=new Random();var w=Windows.Forms.Screen.GetBounds(Point.Empty);for(;;)g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256),r.Next(256),r.Next(256))),r.Next(w.Width),r.Next(w.Height),1,1);}}}
namespace System.Drawing
{
    class P
    {
        static void Main()
        {
            var g = Graphics.FromHdc((IntPtr)0);
            var r = new Random();
            var w = Windows.Forms.Screen.GetBounds(Point.Empty);

            for (;;)
                g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256), r.Next(256), r.Next(256))),
                                r.Next(w.Width), r.Next(w.Height), 1, 1);
        }
    }
}

A version for 308 227 bytes that only draws on the region 0-40:

namespace System.Drawing{class P{static void Main(){var g=Graphics.FromHdc((IntPtr)0);var r=new Random();for(;;)g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256),r.Next(256),r.Next(256))),r.Next(40),r.Next(40),1,1);}}}

C#, 369 288 287 bytes

namespace System.Drawing{class P{static void Main(){var g=Graphics.FromHwnd((IntPtr)0);var w=Windows.Forms.Screen.GetBounds(Point.Empty);for(var r=new Random();;)g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256),r.Next(256),r.Next(256))),r.Next(w.Width),r.Next(w.Height),1,1);}}}
namespace System.Drawing
{
    class P
    {
        static void Main()
        {
            var g = Graphics.FromHdc((IntPtr)0);
            var w = Windows.Forms.Screen.GetBounds(Point.Empty);

            for (var r = new Random();;)
                g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256), r.Next(256), r.Next(256))),
                                r.Next(w.Width), r.Next(w.Height), 1, 1);
        }
    }
}

A version for 308 227 226 bytes that only draws on the region 0-40:

namespace System.Drawing{class P{static void Main(){var g=Graphics.FromHdc((IntPtr)0);for(var r=new Random();;)g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256),r.Next(256),r.Next(256))),r.Next(40),r.Next(40),1,1);}}}
3 deleted 212 characters in body
source | link

C#, 369369 288 bytes

namespace System.Drawing{class P{static void Main(){var g=Graphics.FromHdcFromHwnd(GetDC(0IntPtr)0);var r=new Random();var w=Windows.Forms.Screen.GetBounds(Point.Empty);for(;;)g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256),r.Next(256),r.Next(256))),r.Next(w.Width),r.Next(w.Height),1,1);}[Runtime.InteropServices.DllImport("user32.dll")]static extern IntPtr GetDC(int h);}}

Saved 88 bytes thanks to @CodyGray.

namespace System.Drawing
{
    class P
    {
        static void Main()
        {
            var g = Graphics.FromHdc(GetDC(0IntPtr)0);
            var r = new Random();
            var w = Windows.Forms.Screen.GetBounds(Point.Empty);

            for (;;)
                g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256), r.Next(256), r.Next(256))),
                                r.Next(w.Width), r.Next(w.Height), 1, 1);
        }
 
        [Runtime.InteropServices.DllImport("user32.dll")]
        static extern IntPtr GetDC(int h);
    }
}

A version for 308308 227 bytes that only draws on the region 0-40:

namespace System.Drawing{class P{static void Main(){var g=Graphics.FromHdc(GetDC(0IntPtr)0);var r=new Random();for(;;)g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256),r.Next(256),r.Next(256))),r.Next(40),r.Next(40),1,1);}[Runtime.InteropServices.DllImport("user32.dll")]static extern IntPtr GetDC(int h);}}

C#, 369 bytes

namespace System.Drawing{class P{static void Main(){var g=Graphics.FromHdc(GetDC(0));var r=new Random();var w=Windows.Forms.Screen.GetBounds(Point.Empty);for(;;)g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256),r.Next(256),r.Next(256))),r.Next(w.Width),r.Next(w.Height),1,1);}[Runtime.InteropServices.DllImport("user32.dll")]static extern IntPtr GetDC(int h);}}
namespace System.Drawing
{
    class P
    {
        static void Main()
        {
            var g = Graphics.FromHdc(GetDC(0));
            var r = new Random();
            var w = Windows.Forms.Screen.GetBounds(Point.Empty);

            for (;;)
                g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256), r.Next(256), r.Next(256))),
                                r.Next(w.Width), r.Next(w.Height), 1, 1);
        }
 
        [Runtime.InteropServices.DllImport("user32.dll")]
        static extern IntPtr GetDC(int h);
    }
}

A version for 308 bytes that only draws on the region 0-40:

namespace System.Drawing{class P{static void Main(){var g=Graphics.FromHdc(GetDC(0));var r=new Random();for(;;)g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256),r.Next(256),r.Next(256))),r.Next(40),r.Next(40),1,1);}[Runtime.InteropServices.DllImport("user32.dll")]static extern IntPtr GetDC(int h);}}

C#, 369 288 bytes

namespace System.Drawing{class P{static void Main(){var g=Graphics.FromHwnd((IntPtr)0);var r=new Random();var w=Windows.Forms.Screen.GetBounds(Point.Empty);for(;;)g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256),r.Next(256),r.Next(256))),r.Next(w.Width),r.Next(w.Height),1,1);}}}

Saved 88 bytes thanks to @CodyGray.

namespace System.Drawing
{
    class P
    {
        static void Main()
        {
            var g = Graphics.FromHdc((IntPtr)0);
            var r = new Random();
            var w = Windows.Forms.Screen.GetBounds(Point.Empty);

            for (;;)
                g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256), r.Next(256), r.Next(256))),
                                r.Next(w.Width), r.Next(w.Height), 1, 1);
        }
    }
}

A version for 308 227 bytes that only draws on the region 0-40:

namespace System.Drawing{class P{static void Main(){var g=Graphics.FromHdc((IntPtr)0);var r=new Random();for(;;)g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(256),r.Next(256),r.Next(256))),r.Next(40),r.Next(40),1,1);}}}
2 added 310 characters in body
source | link

I couldn't record this working, with ScreenToGif, as that kept forcing a repaint so the pixels would get removed. However, here is a screenshot of it running after about 10-15 seconds, any longer and I think I may have ground my PC to a halt! The gap in the top right corner is where the screen forced a repaint just as I took the screenshot.

Full version example

Full/Formatted version:

 

I couldn't record this working, with ScreenToGif, as that kept forcing a repaint so the pixels would get removed.

Full/Formatted version:

I couldn't record this working, with ScreenToGif, as that kept forcing a repaint so the pixels would get removed. However, here is a screenshot of it running after about 10-15 seconds, any longer and I think I may have ground my PC to a halt! The gap in the top right corner is where the screen forced a repaint just as I took the screenshot.

Full version example

Full/Formatted version:

 
1
source | link