Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: simple question about random

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58992] Re: [mg58960] Re: simple question about random
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Tue, 26 Jul 2005 04:02:06 -0400 (EDT)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <dbv954$eah$1@smc.vnet.net> <200507250512.BAA04836@smc.vnet.net>
  • Reply-to: murray at math.umass.edu
  • Sender: owner-wri-mathgroup at wolfram.com

For 6 random numbers, not much difference.  But for many, "inefficient" 
hardly does justice to the dramatic performance difference:

    Timing[Table[Random[], {100000}];]
{0.016 Second, Null}

    Timing[rand = {};
    Do[rand = Prepend[rand, Random[]], {100000}];]
{69.984 Second, Null}

ggroup at sarj.ca wrote:
> Hi David,
> 
> Why wouldn't a Do/For loop work?  The following seem to work just fine,
> even if they are somewhat bulky and inefficient.
> 
> rand={};
> Do[rand=Prepend[rand,Random[]],{6}];
> 
> rand1={};
> For[i=1,i=6,i++,rand1=Prepend[rand1,Random[]]];
> 
> I personally would use Table or RandomArray, but...
> 
> 

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: Freeware Mathematica packages(don't know the exact term)
  • Next by Date: Problem with loading SuperWidgetPackage
  • Previous by thread: Re: simple question about random
  • Next by thread: limit problem