Article View: es.comp.os.linux.programacion
Article #9293Re: Numeros aleatorios con c
From: Xavier Montero
Date: Mon, 05 Aug 2002 19:21
Date: Mon, 05 Aug 2002 19:21
41 lines
1857 bytes
1857 bytes
> Me puede alguien poner un ejemplo de como crear numeros aleatorios con
> rand? con turbo c lo se hacer pero en linux no puedo.
Ah� va el ejemplo que pides.
xavi@inspire:~/tmp$ cat main.c
#include <stdio.h> // for printf()
#include <stdlib.h> // for rand()
void main(void)
{
int i; // counter
float res; // result
for( i=0; i<10; i++ )
{
res = float( rand() ) / RAND_MAX;
printf("%f\n", res);
}
}
xavi@inspire:~/tmp$ g++ main.c
xavi@inspire:~/tmp$ a.out
0.840188
0.394383
0.783099
0.798440
0.911647
0.197551
0.335223
0.768230
0.277775
0.553970
xavi@inspire:~/tmp$
> Muchas gracias.
Muchas de nadas.
--
Xavier Montero - Digital Sound Items, scp
Tel: 93 589 71 91 - Fax: 93 590 10 96 - Cell: 630 59 01 62
www.dsitelecom.com - xmontero@dsitelecom.com
Technical Details
Message-ID:
<3D4ED02F.2602103@dsitelecom.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!213-97-61-212.uc.nombres.ttd.ES!not-for-mailReferences:
<3D4CD526.4040201@yaonline.es>Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII X-Google-Thread: f86c8,4b70eab62331a3ee X-Google-Attributes: gidf86c8,public X-Google-ArrivalTime: 2002-08-05 12:32:47 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!213-97-61-212.uc.nombres.ttd.ES!not-for-mail From: Xavier Montero <xmontero@dsitelecom.com> Newsgroups: es.comp.os.linux.programacion Subject: Re: Numeros aleatorios con c Date: Mon, 05 Aug 2002 21:21:19 +0200 Organization: Digital Sound Items Lines: 41 Message-ID: <3D4ED02F.2602103@dsitelecom.com> References: <3D4CD526.4040201@yaonline.es> NNTP-Posting-Host: 213-97-61-212.uc.nombres.ttd.es (213.97.61.212) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: fu-berlin.de 1028575506 38917110 213.97.61.212 (16 [85345]) X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U) X-Accept-Language: en