Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #8480
| Date | 2013-02-25 22:13 +0100 |
|---|---|
| From | Luuk <luuk@invalid.lan> |
| Newsgroups | comp.lang.php |
| Subject | Re: Random function |
| References | <3bbc3c88-ba02-4c72-843a-b87b01bc7c6b@googlegroups.com> <kggj8h$sch$1@yojimbo.hack> |
| Message-ID | <vn0tv9-cj4.ln1@luuk.invalid.lan> (permalink) |
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
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