/// <summary> /// Normal randomly-distributed N-dimensional array elements. /// </summary> /// <param name="dimensions">int array or single int paramters specifying /// dimensions for new array to be created.</param> /// <returns>N-dimensional array filled with random numbers.</returns> /// <remarks>The elements lie within the range 0.0 ... 1.0 and are choosen to be normally /// distributed.</remarks> public static ILArray<double> randn(params int[] dimensions) { ILDimension dim; if (dimensions.Length == 1) dim = new ILDimension(dimensions[0],dimensions[0]); else dim = new ILDimension(dimensions); if (m_nrandomGenerator == null) m_nrandomGenerator = new ILNRandom(Environment.TickCount); double[] data = ILMemoryPool.Pool.New<double>(dim.NumberOfElements); unsafe { fixed (double* pRetArray = data) { double* pCurIdx = pRetArray; double* pLastElement = pCurIdx + dim.NumberOfElements; while (pCurIdx < pLastElement) *pCurIdx++ = m_nrandomGenerator.NextDouble(); } } return new ILArray<double>(data, dim); }
/// <summary> /// Set seed to both rand and randn functions /// </summary> /// <param name="seed">Any ole' number will do</param> public static void setseed(int seed) { m_nrandomGenerator = new ILNRandom(seed); m_randomGenerator = new Random(seed); }