Информационный сервер для программистов: Исходники со всего света. Паскальные исходники со всего света
  Powered by Поисковый сервер Яndex: Найдется ВСЁ!
На Главную Исходники Форум Информер Страны мира
   Математика    >>    nrand2
   
 
 NRand - Normally-Distributed Random Number Generator  Unknown 15.02.1992

Функция - генератор случайных чисел с нормальным распределением.
NRand --- Return normally-distributed random number



1k 
 

(*--------------------------------------------------------------*) (* NRand --- Return normally-distributed random number *) (*--------------------------------------------------------------*) FUNCTION NRand( Mean : REAL; StdDev : REAL ) : REAL; (*--------------------------------------------------------------*) (* *) (* Function: NRand *) (* *) (* Purpose: Returns normally distributed random number. *) (* *) (* Calling sequence: *) (* *) (* Ran := NRand( Mean : REAL; StdDev : REAL ) : REAL; *) (* *) (* Mean --- Mean of normal distribution *) (* StdDev --- Standard deviation of normal distribution *) (* Ran --- Resultant random number *) (* *) (* Method: *) (* *) (* The Box-Muller transformation is used to get two normal *) (* (0,1)-distributed values. The given mean and standard *) (* deviation are used to scale the results to (Mean, StdDev).*) (* The first random number is returned by this call, and the *) (* second random number by the next call. *) (* *) (*--------------------------------------------------------------*) (* STATIC VARIABLES *) CONST NRand_Available : BOOLEAN = FALSE (* If number already available -- *); Saved_NRand : REAL = 0.0 (* saved from last time through. *); VAR V1 : REAL; V2 : REAL; R : REAL; Fac: REAL; BEGIN (* NRand *) (* Return 2nd random number calculated *) (* last time through here. *) IF NRand_Available THEN