Article View: chile.comp.programacion
Article #3276Re: duda numeros aleatorios php
From: Rickoj
Date: Thu, 31 Mar 2005 23:54
Date: Thu, 31 Mar 2005 23:54
28 lines
1889 bytes
1889 bytes
En las news:87wtrnxzzh.fsf@guti.no-ip.org, a Cristian Gutierrez se le ocurrio tipear: > Hoy en la tarde, Rick oj dijo: >> se que es un poco basico pero no se cual es mi error estoy generando numeros >> aleatorios y guardandolos en un arreglo >> >> srand(time()); >> $numeros=array_fill(0,21,rand(1,100)); >> >> con esta funcion me guarda el mismo numero siempre >> >> en cambio si lo hago en un ciclo >> >> $numeros = array (); >> srand(time()); >> for ($i = 0; $i < 21; $i++) >> $numeros[$i] = rand (1, 100); >> >> me entrega valores diferentes, estoy utilizando mal la funcion array_fill ? > > Exacto. array_fill no va a llamar a rand(1,100) 20 veces, sino que el > interprete de PHP llama a rand(1,100), obtiene un valor, y ese es el que > se lleva array_fill. Recuerda se evalua "de adentro hacia afuera". grax, tampoco serviria crear una funcion a ser llamada ? por que tambien estaria entregando el mismo numero
Technical Details
Message-ID:
<d2i2p6$sj1$1@news1.nivel5.cl>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!nntp-server.pubsub.com!news1.nivel5.cl!not-for-mailReferences:
<d2hg51$mt2$1@news1.nivel5.cl> <87wtrnxzzh.fsf@guti.no-ip.org>Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,75664339df4cdcff X-Google-Attributes: gid1593cb,public X-Google-Language: SPANISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!nntp-server.pubsub.com!news1.nivel5.cl!not-for-mail From: "Rick_oj" <rick_oj@[sin-esto]tutopia.com> Newsgroups: chile.comp.programacion Subject: Re: duda numeros aleatorios php Date: Thu, 31 Mar 2005 19:54:26 -0400 Organization: Varios Lines: 30 Message-ID: <d2i2p6$sj1$1@news1.nivel5.cl> References: <d2hg51$mt2$1@news1.nivel5.cl> <87wtrnxzzh.fsf@guti.no-ip.org> NNTP-Posting-Host: pc-154-157-104-200.cm.vtr.net X-Trace: news1.nivel5.cl 1112313446 29281 200.104.157.154 (31 Mar 2005 23:57:26 GMT) X-Complaints-To: news@news1.nivel5.cl NNTP-Posting-Date: Thu, 31 Mar 2005 23:57:26 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1478 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1478