Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.019 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'skip:[ 20': 0.03; 'float': 0.05; 'subject:How': 0.09; 'subject:create': 0.09; 'subject:python': 0.11; '100,': 0.16; 'subject:array': 0.16; 'subject:random': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'work.': 0.23; 'random': 0.24; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'values': 0.26; 'am,': 0.27; 'gary': 0.29; 'array': 0.29; 'to:addr:python-list': 0.33; 'but': 0.36; 'does': 0.37; 'skip:3 10': 0.37; 'skip:4 10': 0.37; 'subject:: ': 0.38; 'received:10': 0.38; 'science': 0.38; 'to:addr:python.org': 0.39; 'dr.': 0.72; 'institute': 0.72; 'received:204': 0.72; 'received:10.10': 0.75; '10:11': 0.84; 'ranging': 0.91 Date: Tue, 12 Mar 2013 10:26:35 -0700 From: Gary Herron User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130221 Thunderbird/17.0.3 MIME-Version: 1.0 To: python-list@python.org Subject: Re: How can i create a random array of floats from 0 to 5 in python References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1363109706 news.xs4all.nl 6885 [2001:888:2000:d::a6]:60012 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41138 On 03/12/2013 10:11 AM, Norah Jones wrote: > I want to create a random float array of size 100, with the values in > the array ranging from 0 to 5. I have tried > random.sample(range(5),100) but that does not work. How can i get what > i want to achieve? > > >>> [random.uniform(0,5) for i in range(100)] [0.035440065542497456, 1.437405027400226, 4.3729265564939235, 1.8571876890801535, 3.3707291675828355, 3.8527038142772803, 2.335308526527048, 1.6648256912958126, 2.619282525564386, 0.49146229156297017, 0.44118757769151584, 4.739666518393803, 2.382053744691543, 0.49644235270002446, 3.2450874430280967, 2.907453418492667, 4.476790608458042, 3.6331854165844604, 4.048234752835737, 1.0561381241342283, 2.812909536326582, 3.561597391575344, 2.6487355099594017, 0.29397014028037627, 2.4479483428627753, 3.958448741888134, 2.407241234096458, 1.3214223763910538, 2.13697973410729, 0.5948251249983533, 1.7529836288331397, 1.5086813377327446, 1.8586362776340244, 1.2208704263132752, 0.641484635760266, 1.3848412838385726, 0.9293523709719054, 2.186001913964843, 4.573380203193875, 2.139476734752273, 2.9472883699144536, 2.896233361842901, 3.6862386168483736, 0.34731746668937247, 0.32240948705737016, 3.5558945043043533, 3.2122777306650474, 4.361615595368701, 0.015650980269780734, 3.6657002416980946, 2.559029702763296, 3.1821909947792215, 1.110074378492174, 4.631074891897119, 0.34141410223593516, 4.857392826027885, 3.527794364975918, 1.1557966421173278, 3.052715879227505, 3.5157974813529522, 1.1124961331040095, 0.3481541778415814, 4.669841649649461, 0.5971397176504589, 2.558151735886299, 1.2604807126742945, 2.281602331386756, 2.1519211043558695, 3.3468967934451657, 1.8240743647766071, 2.91696855571327, 0.6894263573879533, 2.7732038929294616, 4.783919829213994, 4.082864012400709, 0.16128311206877133, 4.959480373070126, 2.8458909583600187, 4.494888799994467, 4.647426388056034, 3.111088594459788, 4.261340689865024, 1.6013438490852865, 3.6386026965034852, 1.212916907042898, 3.3586184962657706, 3.6105733007635954, 0.5372141790624257, 0.9433843973095679, 3.113889114931214, 3.054082222169326, 2.360224809741029, 2.026697918525358, 1.322913986495805, 4.341848866805052, 0.970311202088483, 2.002058149505537, 0.07453277198439523, 1.9633241018322773, 4.22967258746455] -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418