FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Random function
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Random function [message #180554 is a reply to message #180546] Tue, 26 February 2013 01:46 Go to previous messageGo to previous message
Robert Heller is currently offline  Robert Heller
Messages: 60
Registered: December 2010
Karma:
Member
At Mon, 25 Feb 2013 22:13:04 +0100 Luuk <luuk(at)invalid(dot)lan> wrote:

>
> On 25-02-2013 21:57, Salvatore wrote:
>> On 2013-02-25, sonnichjensen(at)gmail(dot)com <sonnichjensen(at)gmail(dot)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......

bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
(72+134)/2
103

The average of just those two data points is 103, and given that the
number of samples generated was 100 times the range of values, this is
reasonable.

Note:

sh# php -f rand.php | sort | uniq -c | wc -l
1808

All 1808 possible values were hit. From an eyeball look at the counts,
I'd guess that average hit count would be about 100, which suggests a
reasonable distrubution.

It is important to know: properly functioning computers are never truely
random. These random number generators are called 'psuedo' random
number generators for a reason. The sort of generators used for common
programming language run-time libraries are not to be considered
anything close to the ballpark of the sort used by secure encryption
software (eg OpenSSL, ssh, PGP, GPG, etc.). They are generally good
enough for things like computer games.

>
>
> $ 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
>
>
>
>

--
Robert Heller -- 978-544-6933 / heller(at)deepsoft(dot)com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Request for proofreading
Next Topic: XML error when accessing a certain method of a wsdl service
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 18:54:35 GMT 2024

Total time taken to generate the page: 0.03373 seconds