[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] gauss fordelt rand()



Sune Fischer <sslug@sslug> writes:
> Er der nogen der kan huske, hvordan man får ligefordelingen lavet om
> til fx. en gaussfordeling?

Det kommer an på hvor hurtigt den hele skal gå, og hvor gode
resultater du vil have. Den følgende metode giver resultater der er så
gode at det er svært at se forskel med det blotte øje (i gnuplot). Det
går ret hurtigt fordi man ikke har brug for så mange gange operationer

double gauss() {
  const int Ngauss = 12
  double Sum=0.0;
  for (int i=0; i<Ngauss; i++) 
        Sum += RandUnit();
  return (Sum - 0.5 * Ngauss) * pow(Ngauss,-0.5);
}

Held og lykke :)

PS: Jeg har skrevet funktionen frit efter hukommelsen. Husk at teste
den af før du putter den ind i dit program. 

PPS: Efter sigende er talgeneratoren i de fleste compilere ikke
særligt god. Jeg ved ikke om det er rigtigt, eller om de er blevet
bedre med tiden. Ellers kan du sikkert finde en god generator på
http://www.netlib.org



-- 
Niels L Ellegaard  http://dirac.ruc.dk/~gnalle/
SPECIAL OFFER! I proofread unsolicited commercial email sent to this
address at a rate of US $500.00 per incident!  Include billing address
in your message and save US $500.00 per hour off ordinary address
resolution and tracking charge!


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *