Hi, How could i generate random real numbers between 0 en 2*pi? Thanks, Frederik [[alternative HTML version deleted]]
On Tue, 2 Mar 2010 11:51:39 +0100 frederik vanhaelst <frederik.vanhaelst at gmail.com> wrote:> How could i generate random real numbers between 0 en 2*pi?Ten such numbers from the uniform distribution: 2*pi*runif(10) -- Karl Ove Hufthammer
> runif(20,0,2*pi)[1] 1.29417642 1.10933879 4.31669186 2.41339484 4.83705630 3.12713657 4.50893007 6.23232980 2.38783146 4.88483239 5.87292617 [12] 1.33293077 4.09458703 0.78888593 1.67899698 2.42602639 0.08413394 2.40261439 5.46442874 2.13847582>On Tue, Mar 2, 2010 at 5:51 AM, frederik vanhaelst <frederik.vanhaelst at gmail.com> wrote:> Hi, > > How could i generate random real numbers between 0 en 2*pi? > > Thanks, > > Frederik > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
>From what distribution?If the uniform, runif(100,0,2*pi) If another, install package Runuran, and do this ?Runuran Vignette("Runuran") HTH ____________________________________________________________________________________ Dr. Rub?n Roa-Ureta AZTI - Tecnalia / Marine Research Unit Txatxarramendi Ugartea z/g 48395 Sukarrieta (Bizkaia) SPAIN -----Mensaje original----- De: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] En nombre de frederik vanhaelst Enviado el: martes, 02 de marzo de 2010 11:52 Para: R-help at stat.math.ethz.ch Asunto: [R] Random real numbers Hi, How could i generate random real numbers between 0 en 2*pi? Thanks, Frederik [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
frederik vanhaelst wrote:> Hi, > > How could i generate random real numbers between 0 en 2*pi? > > Thanks, > > Frederik > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >Googeling for "R generate random number" gave this as a second hit (on my machine): http://blog.revolution-computing.com/2009/02/how-to-choose-a-random-number-in-r.html cheers, Paul -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul
Well, to be mathematically correct, you cannot choose random real numbers for the simple reason that we don't even have names for all the reals. As all of you know (I hope :-) ), there are the same number (aleph-1) of reals in any length line segment you wish. Aside from the unlikelihood that you could write a random number generator that produced, say, (3.14159^5.432- .3289^3.19847)^(0.274) , there are a whole pile of transcendentals that you'll never get. So as always, settle for a random rational number amongst the 2^N values your floating point processor can actually produce. Carl