Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #8480

Re: Random function

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Date Mon, 25 Feb 2013 22:13:04 +0100
From Luuk <luuk@invalid.lan>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130215 Thunderbird/17.0.3
MIME-Version 1.0
Newsgroups comp.lang.php
Subject Re: Random function
References <3bbc3c88-ba02-4c72-843a-b87b01bc7c6b@googlegroups.com> <kggj8h$sch$1@yojimbo.hack>
In-Reply-To <kggj8h$sch$1@yojimbo.hack>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Message-ID <vn0tv9-cj4.ln1@luuk.invalid.lan> (permalink)
Lines 35
NNTP-Posting-Host 2001:980:9089:1:60ff:122:1e2f:115c
X-Trace 1361827201 news.xs4all.nl 6962 [2001:980:9089:1:60ff:122:1e2f:115c]:49088
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.php:8480

Show key headers only | View raw


On 25-02-2013 21:57, Salvatore wrote:
> On 2013-02-25, sonnichjensen@gmail.com <sonnichjensen@gmail.com> wrote:
>> Hi
>>
>> I use the rand function to get 10 items of 1808 current itemes. I tried some 50 times or so and I can clearly see that it has a few "faivourite numbers" which comes all the time, and some whihc I still have to see (I am talking about large groups of items from the 1808 picture, that I still have to see)
>>
>> How I can get a better random function?
>
> Try mt_rand().
>


file: rand.php
<?php
         for ($x=1; $x<=180800; $x++) {
                 echo mt_rand(1,1808)."\n";
         }
?>

bash:
$ php -f rand.php | sort | uniq -c | awk 'BEGIN {m=9999; r=0; }{ if 
($1<m) { m=$1; }; if ($1>r) { r=$1; }} END{ print m,r; }'
72 134

This means that some number only was picked 72 times,
and another number was picked 134 times......


$ php -version
PHP 5.3.8 (cli)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies


Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Random function sonnichjensen@gmail.com - 2013-02-25 12:48 -0800
  Re: Random function Salvatore <sal@yojimbo.hack.invalid> - 2013-02-25 20:57 +0000
    Re: Random function Luuk <luuk@invalid.lan> - 2013-02-25 22:13 +0100
      Re: Random function Jerry Stuckle <jstucklex@attglobal.net> - 2013-02-25 16:42 -0500
      Re: Random function The Natural Philosopher <tnp@invalid.invalid> - 2013-02-25 22:12 +0000
      Re: Random function Robert Heller <heller@deepsoft.com> - 2013-02-25 19:46 -0600
  Re: Random function Jerry Stuckle <jstucklex@attglobal.net> - 2013-02-25 16:39 -0500
  Re: Random function The Natural Philosopher <tnp@invalid.invalid> - 2013-02-25 22:11 +0000
  Re: Random function Salvatore <sal@yojimbo.hack.invalid> - 2013-02-25 22:42 +0000
    Re: Random function "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-02-26 11:18 +0100
      Re: Random function Paul Herber <paul@pherber.com> - 2013-02-26 13:52 +0000
    Re: Random function Markus Grob <snoopy@ilnet.ch> - 2013-02-27 12:17 +0100
      Re: Random function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-02-28 00:22 +0100

csiph-web