[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



Hey....

kunne man ikke:

#define RAND_MAX 100
if( tal < rand() ) return 0;
else return 1;

ellers ender i med at sammenligne integers mellem 0 og 1. Med den
tidligere konstruktion vil "rand/RAND_MAX" altid være 0. Det vil
"tal/100" også.

Måske tager jeg fejl.....

M.v.h.
Søren


sslug@sslug wrote:
> 
> Tusind tak for forslagene,
> 
> men uanset om jeg benytter:
> 
> if ((tal/100) > (rand()/RAND_MAX)) return 1;
> else return 0;
> 
> eller:
> 
> if(rand() < RAND_MAX * tal/100) return 1; else return 0;
> 
> returnerer funktionen stort set altid 0!
> 
> Hvis jeg ændrer på funktionerne fx. und lader at dividere med 100 svarer
> funktionen altid 1, medmindre tal=0.
> 
> Hvis jeg dividerer med 50 istedet for 100 svarer funktionen 0 for
> halvdelen og 1 for resten.
> 
> Men uanset disse ændringer, svarer funktionen det samme, for det samme
> 'tal'. Det vil sige, der er 100% sandsynlighed for det samme svar og ikke
> tallets værdi procent sandsynlighed, som det var meningen.
> 
> Med venlig hilsen
> Marie Louise


 
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] *