[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] 'sandsynligheds'-funktion



sslug@sslug wrote:
Hej c-liste

 Jeg skal lave en sandsynligheds-funktion, der givet et tal imellem 0 og
 100, returnerer 1 med <tal>% sandsynlighed, og 0 med <100 - tal>%
 sandsynlighed.

 dvs. givet tallet 40 skal funktionen returnere 1 40% af gangene, og 0 60%
 af gangene, funktionen bliver kaldt.

Har I nogle gode ideer til, hvordan det kan lade sig gøre?

 Med venlig hilsen
 Marie Louise




se: man rand


Den giver dig et pseudo-tilfældigt tal mellem 0 og RAND_MAX
Så er det blot at lave en spørgesætning a la:

if(tal < RAND_MAX x 40%) return 1;
else return 0;

/Egon



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 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] *