Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Community > Forum De Bell Tolls > [C]Rand() Thread Rating: 1 votes, 5.00 average.
  Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
nous
.:Retore Pomposo:.

User info:
Registered: Dec 2001
Posts: 2945 (0.33 al dì)
Location: Fino Mornasco - Como
Corso: Informatica
Anno: Specialista
Time Online: 16 Days, 13:56:49 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
[C]Rand()

Un piccolo problema con il C... devo generare n numeri random uniformemente distribuiti in (0,1).
Sapendo dell'esistenza di drand48() che proprio di questo si occupa, l'ho utilizzata. Senonchè non è possibile inizializzare drand48() passandogli un valore come si fa comunemente con rand().
Allorchè ho pensato : uso rand(time(NULL))/MAX_RAND e ottengo dei valori uniformemente distribuiti tra [0,1] , probabilmente non mi usciranno mai lo 0 e l'1 e quindi vabbene lo stesso perchè almeno inizializzo il generatore di numeri random in maniera diversa ad ogni lancio del programma.
Ma , incredibile dictu, mi da dei problemi proprio sul time(NULL), il problema lo posto estensivamente domani ma fondamentalkmente non funziona se non eliminando time(NULL), e a quel punto tanto vale usare drand48() che mi genera un intervallo aperto.
Tutto chiaro, no?Avete idee??Il sistema operativo è ovviamente Linux, Red Hat 9.Grazie a chi mi aiuta.

__________________
Cristian,il Nous che invoglia ^_^

"La capa è troppo in la,e la sbarba è troppo giovane..mi sa che qua si va in bianco"
Ryo Saeba (City Hunter)

08-01-2004 13:59
Click Here to See the Profile for nous Click Here to See the Blog of nous Click here to Send nous a Private Message Visit nous's homepage! Find more posts by nous Add nous to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Gwath
.:Interstate.60:.

User info:
Registered: Mar 2003
Posts: 2495 (0.30 al dì)
Location: Verona (abito a Mi)
Corso: Info
Anno: ...meglio non dirlo...
Time Online: 25 Days, 11:41:08: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

hai provato a inizializzare il seme con srand(valore) e poi a fare rand()/MAX_RAND ???

__________________
L'ombra si nasconde nella notte, laddove neanche l'occhio piu' allenato riesce a scorgerla...
:teach:Homo sapiens non urinat in ventum:teach: Non c'è birra senza spina :teach: La vita e` il dono piu` prezioso che Giove ci ha fatto (Ali G) :teach:
Mastro Birromane della Falange Alcolica...
Gwath Lumbule... as darkness falls, he comes out! Dark Shadow's Blog
:roargh: Tu mi dai la forza per andare avanti... Non fermarti continua a spingere!!!:roargh:

08-01-2004 14:02
Click Here to See the Profile for Gwath Click Here to See the Blog of Gwath Click here to Send Gwath a Private Message Find more posts by Gwath Add Gwath to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Renaulto
is fan of UTF-8

User info:
Registered: Aug 2002
Posts: 4064 (0.47 al dì)
Location:
Corso: Informatica
Anno:
Time Online: 96 Days, 0:23:57 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

e' vero, prima devi inseminarlo con srand()

__________________
Tanenbaum is overrated.

08-01-2004 14:19
Click Here to See the Profile for Renaulto Click Here to See the Blog of Renaulto Click here to Send Renaulto a Private Message Find more posts by Renaulto Add Renaulto to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
lorenzo
...ma anche no.

User info:
Registered: Jun 2002
Posts: 3149 (0.37 al dì)
Location: Milano
Corso: F49
Anno: 00000011
Time Online: 49 Days, 1:47:46 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Semmai srand48(long seed), o meglio seed48(unsigned short seed[3]), che come parametro vuole un vettore con i 3 interi che compongono il seme da 48 bit, e ritorna il puntatore al vecchio seme (di cui puoi anche fregartene bellamente).

Ma non ho capito se tu vuoi un intervallo aperto o chiuso... drand48 ti dà un double nell'intervallo [0, 1) mi pare.


EDIT:
Che poi, se il problema è con la time(), continuerà a esserci visto che probabilmente userà la stessa funzione per inizializzare il seme (inizializzare con una costante non ha molto senso...)

__________________
Non ti laureare, continua a cazzeggiare!

"È tutta merda..." - clod81

Last edited by lorenzo on 12-01-2004 at 15:13

08-01-2004 15:31
Click Here to See the Profile for lorenzo Click Here to See the Blog of lorenzo Click here to Send lorenzo a Private Message Visit lorenzo's homepage! Find more posts by lorenzo Add lorenzo to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
AlphaGamma
.piano ma pieni.

User info:
Registered: Jun 2002
Posts: 6732 (0.78 al dì)
Location:
Corso: Eh?
Anno: Io cosa?
Time Online: 21 Days, 21:22:01: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Nous, sei andato a vederlo il mio generatore percorsi? :D
Li faceva random, non ricordo come, ma randomizzava bene. :)

http://www.dsy.it/forum/showthread.php?s=&threadid=2606

__________________
Attenzio', concentrazio', ritmo e VITALITÀ

08-01-2004 23:58
Click Here to See the Profile for AlphaGamma Click Here to See the Blog of AlphaGamma Click here to Send AlphaGamma a Private Message Visit AlphaGamma's homepage! Find more posts by AlphaGamma Add AlphaGamma to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 04:01.    Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.237 seconds (42.99% PHP - 57.01% MySQL) con 25 query.