Skip to main content

Posts

Showing posts from 2010

Local IP Address

Here is a usefull block of code to retrieve a host IPAddress: private static class Network { #region DNS public static IPAddress FindIPAddress( bool localPreference) { return FindIPAddress( Dns .GetHostEntry( Dns .GetHostName()), localPreference); } public static IPAddress FindIPAddress( IPHostEntry host, bool localPreference) { if (host == null ) throw new ArgumentNullException ( "host" ); if (host.AddressList.Length == 1) return host.AddressList[0]; else { foreach (System.Net. IPAddress address in host.AddressList) { bool local = IsLocal(address); if (local && localPreference) return address; ...

Understanding Monte Carlo Simulation C#

This method has been introduced to resolve numerically complex physics problems, such as neutron diffusion, that were to complex for an analytical solution. This method is based on generating random values for parameters or inputs to explore the behaviour of complex systems, now this method is used in various domains like: Engineering, science and finance. These approaches tend to follow a particular pattern: 1- Define a domain of possible inputs. 2- Generate inputs randomly from the domain using a certain specified probability distribution. 3- Perform a deterministic computation using the inputs. 4- Aggregate the results of the individual computations into the final result. Here is an example of using Monte Carlo simulation to approximate the value of Pi: In this case we have 2 parameters x,y which defines a location in the plane (e.g The picture on the left). We will calculate the probability to have a point in the 1/4 Circle area, with a radius of 1. To calculate Pi we...