Hi Everyone, I did a quick search of the list and it looks like this may not have been asked before... I'm trying to generate a matrix of random numbers between 0 and 1, with 6 columns, 10000 rows. About all I know is that runif(1) gives me the random number I'm looking for. Any help would be great! thanks, -Max
m <- runif(60000) mm <- matrix(m, ncol=6) HTH Dave On Thu, Jul 31, 2008 at 6:24 PM, Max <mnevill@exitcheck.net> wrote:> Hi Everyone, > > I did a quick search of the list and it looks like this may not have been > asked before... I'm trying to generate a matrix of random numbers between 0 > and 1, with 6 columns, 10000 rows. About all I know is that runif(1) gives > me the random number I'm looking for. > > Any help would be great! > > thanks, > > -Max > > ______________________________________________ > R-help@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. >-- David Barron Said Business School Park End Street Oxford OX1 1HP 01865 288906 [[alternative HTML version deleted]]
on 07/31/2008 12:24 PM Max wrote:> Hi Everyone, > > I did a quick search of the list and it looks like this may not have > been asked before... I'm trying to generate a matrix of random numbers > between 0 and 1, with 6 columns, 10000 rows. About all I know is that > runif(1) gives me the random number I'm looking for. > > Any help would be great! > > thanks,MAT <- matrix(runif(10000 * 6), 10000, 6) > str(MAT) num [1:10000, 1:6] 0.753 0.600 0.806 0.713 0.796 ... > head(MAT, 10) [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0.75343430 0.4993896 0.68554749 0.01924549 0.90579982 0.99606191 [2,] 0.59957219 0.4075650 0.57851744 0.97208426 0.32137505 0.02089689 [3,] 0.80567935 0.5746030 0.16520072 0.92615138 0.01628994 0.90075333 [4,] 0.71270574 0.3252210 0.53765089 0.58930899 0.03053356 0.23282879 [5,] 0.79603691 0.5591622 0.97308348 0.52744458 0.76403708 0.22268021 [6,] 0.49624259 0.5106604 0.06687444 0.48659150 0.29803454 0.91760758 [7,] 0.32921909 0.7784539 0.20468873 0.86730697 0.42581735 0.59344279 [8,] 0.93646405 0.4819996 0.79033546 0.68441917 0.28566573 0.97244395 [9,] 0.02964297 0.5489500 0.64355067 0.87131530 0.58505804 0.06972828 [10,] 0.55956266 0.8376349 0.11850374 0.37687892 0.71220844 0.97784727 The first argument to runif() is how many random deviates you want to generate. If you need to be able to reproduce the exact sequence again in the future, see ?set.seed. HTH, Marc Schwartz
Hi All, I have a few queries regarding Random Number generation in R. according to the help(Random.User) i defined my own functions for user_unif_rand and user_norm_rand (uniform and normal distribution) But what i figured out was even when i call rexp,rpois,rgeom and other distributions they were routed via user_unif_rand. 1. Does this mean that for all types of distribution it generates an Uniform distribution and transforms to the requested type? Also surprisingly even rnorm which i hoped to route via user_norm_rand was calling user_unif_rand...> rnorm(1)inside user_unif_rand//printf and inside user_unif_rand [1] 0.5973648 Please help me out understanding this... 2. Our goal is to link with an vectorized Random number generator library for our multi-core architecture. So is it enough if we define user_unif_rand function alone and will it take care of all distributions? Thanks in Anticipation, R. Subramanian [[alternative HTML version deleted]]
Please don't cross-post. This reply is going to R-devel only. On 8/5/2008 8:47 AM, subramanian R wrote:> Hi All, > I have a few queries regarding Random Number generation in R. > according to the help(Random.User) i defined my own functions forThat's help("Random.user")...> user_unif_rand and user_norm_rand (uniform and normal distribution) > > But what i figured out was even when i call rexp,rpois,rgeom and > other distributions they were routed via user_unif_rand. > 1. Does this mean that for all types of distribution it generates an > Uniform distribution and transforms to the requested type? > > Also surprisingly even rnorm which i hoped to route via user_norm_rand > was calling user_unif_rand... > > >> rnorm(1) > inside user_unif_rand//printf and > inside user_unif_rand > [1] 0.5973648 > > > Please help me out understanding this...I think you didn't do things properly, but you didn't show us what you did. When I run the sample code in help("Random.user"), adding an Rprintf() call to the user_norm_rand function, I see it being called. Duncan Murdoch> > 2. Our goal is to link with an vectorized Random number generator library > for our multi-core architecture. > So is it enough if we define user_unif_rand function alone and will it > take care of all distributions? > > > Thanks in Anticipation, > R. Subramanian > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Please don't cross-post. I've replied in R-devel. On 8/5/2008 8:47 AM, subramanian R wrote:> Hi All, > I have a few queries regarding Random Number generation in R. > according to the help(Random.User) i defined my own functions for > user_unif_rand and user_norm_rand (uniform and normal distribution) > > But what i figured out was even when i call rexp,rpois,rgeom and > other distributions they were routed via user_unif_rand. > 1. Does this mean that for all types of distribution it generates an > Uniform distribution and transforms to the requested type? > > Also surprisingly even rnorm which i hoped to route via user_norm_rand > was calling user_unif_rand... > > >> rnorm(1) > inside user_unif_rand//printf and > inside user_unif_rand > [1] 0.5973648 > > > Please help me out understanding this... > > 2. Our goal is to link with an vectorized Random number generator library > for our multi-core architecture. > So is it enough if we define user_unif_rand function alone and will it > take care of all distributions? > > > Thanks in Anticipation, > R. Subramanian > > [[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.