Re: [PHP] Rand() problem

2004-01-11 Thread Jason Wong
On Monday 12 January 2004 12:30, Jon wrote:
> I am running the latest stable PHP release.

Which is? "Latest" changes over time. Always state the exact version. 

>  I am passed values and my
> range is far less than the max...  On my computer with my Xitami webserver
> this code returns the number 45 over and over:
>
> $num = rand(0,50);
> echo $num;
>
> I don't know what to do.  The rand function worked a few times then died on
> me.  I dunno if this is a bug or if I am just bad luck. Never had a problem
> before.  It seems that on a different computer it returns a different
> number than 45 but always the same number over and over.

If you are using a relatively new version of PHP then there is no need to seed 
the random number generator. And it is better to use mt_rand() rather than 
rand() because:

- it is supposed to produce better random numbers
- is faster than rand()


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
No evil can happen to a good man.
-- Plato
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Rand() problem

2004-01-11 Thread Jon
I am running the latest stable PHP release.  I am passed values and my range
is far less than the max...  On my computer with my Xitami webserver this
code returns the number 45 over and over:

$num = rand(0,50);
echo $num;

I don't know what to do.  The rand function worked a few times then died on
me.  I dunno if this is a bug or if I am just bad luck. Never had a problem
before.  It seems that on a different computer it returns a different number
than 45 but always the same number over and over.

- Original Message - 
From: "Richard Davey" <[EMAIL PROTECTED]>
To: "nefar" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Saturday, January 10, 2004 5:26 AM
Subject: Re: [PHP] Rand() problem


> Hello nefar,
>
> Friday, January 9, 2004, 6:05:34 AM, you wrote:
>
> n> After moving my PHP files to a new hard drive and a new windows
> n> installation, my rand function gets stuck and only gives you one number
over
> n> and over.  It worked a few times then got stuck.  I tried using IIS 5.1
(I
> n> was using Xitami) and it gave me the same results.  It even gets stuck
on
> n> the same number as the other webserver. I tried installing on a
different
> n> machine.  Same result.  Can anyone help?
>
> Which version of PHP are you using? If it's earlier than 4.2.0 you
> need to see the rand() function first, or it will return the same
> numbers each time. Use srand() to do this.
>
> Also, are you passing in values to the rand() function? (your min and
> max values) - on Windows there is a limit on the max value of 32,768.
>
> -- 
> Best regards,
>  Richardmailto:[EMAIL PROTECTED]
>
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Rand() problem

2004-01-10 Thread Richard Davey
Hello nefar,

Friday, January 9, 2004, 6:05:34 AM, you wrote:

n> After moving my PHP files to a new hard drive and a new windows
n> installation, my rand function gets stuck and only gives you one number over
n> and over.  It worked a few times then got stuck.  I tried using IIS 5.1 (I
n> was using Xitami) and it gave me the same results.  It even gets stuck on
n> the same number as the other webserver. I tried installing on a different
n> machine.  Same result.  Can anyone help?

Which version of PHP are you using? If it's earlier than 4.2.0 you
need to see the rand() function first, or it will return the same
numbers each time. Use srand() to do this.

Also, are you passing in values to the rand() function? (your min and
max values) - on Windows there is a limit on the max value of 32,768.

-- 
Best regards,
 Richardmailto:[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] rand() function not working right

2003-08-31 Thread john
hope not ... winxp


- Original Message - 
From: "Curt Zirzow" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, August 31, 2003 5:13 PM
Subject: Re: [PHP] rand() function not working right


> * Thus wrote john ([EMAIL PROTECTED]):
> > youre not the only one .. i just installed 4.3.3 and $x = rand(1,173);
> > always returns 101 for $x
> > 
> > i changed to mt_rand(1,173); and that always returns 142  ???
> > 
> > weirdness .. dont tell me this is happening to only me?
> 
> it works find with 4.3.3RC1 on unix.  I'm curious if this is an OS
> issue, what OS are you running php on?
> 
> 
> 
> Curt
> -- 
> "I used to think I was indecisive, but now I'm not so sure."
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] rand() function not working right

2003-08-31 Thread Curt Zirzow
* Thus wrote john ([EMAIL PROTECTED]):
> youre not the only one .. i just installed 4.3.3 and $x = rand(1,173);
> always returns 101 for $x
> 
> i changed to mt_rand(1,173); and that always returns 142  ???
> 
> weirdness .. dont tell me this is happening to only me?

it works find with 4.3.3RC1 on unix.  I'm curious if this is an OS
issue, what OS are you running php on?



Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] rand() function not working right

2003-08-31 Thread John T. Beresford
I can confirm that the funtion works fine using php 4.3.0. on Mac OS X.

While this may not be of any help, I will test on a later install on 
a test server.

Thanks,
John
At 4:15 PM +1000 8/31/03, john wrote:
youre not the only one .. i just installed 4.3.3 and $x = rand(1,173);
always returns 101 for $x
i changed to mt_rand(1,173); and that always returns 142  ???

weirdness .. dont tell me this is happening to only me?



- Original Message -
From: <[EMAIL PROTECTED]>
To: "php general list" <[EMAIL PROTECTED]>
Sent: Thursday, May 29, 2003 4:29 AM
Subject: [PHP] rand() function not working right

 I'm using the latest php and the rand() function isn't working properly
when
 giving it any min and max arguments.
 It does work without anything between the () but if I put a min and max,
 then only the min value always gets chosen.
 Is that a bug? Is that new?

 I'm not using an old php version, and it makes no difference to seed or
not.
 I've switched to mt_rand() and it seems to work fine with min/max so far..

 --
 Didier Godefroy
 mailto:[EMAIL PROTECTED]
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
===
John T. Beresford
Apple Certified Technical Coordinator
http://www.deewi.com/
405.760.0794
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] rand() function not working right

2003-08-31 Thread john
youre not the only one .. i just installed 4.3.3 and $x = rand(1,173);
always returns 101 for $x

i changed to mt_rand(1,173); and that always returns 142  ???

weirdness .. dont tell me this is happening to only me?



- Original Message - 
From: <[EMAIL PROTECTED]>
To: "php general list" <[EMAIL PROTECTED]>
Sent: Thursday, May 29, 2003 4:29 AM
Subject: [PHP] rand() function not working right


> I'm using the latest php and the rand() function isn't working properly
when
> giving it any min and max arguments.
> It does work without anything between the () but if I put a min and max,
> then only the min value always gets chosen.
>
> Is that a bug? Is that new?
>
> I'm not using an old php version, and it makes no difference to seed or
not.
> I've switched to mt_rand() and it seems to work fine with min/max so far..
>
> -- 
> Didier Godefroy
> mailto:[EMAIL PROTECTED]
>
>
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] rand()

2002-03-13 Thread Niklas Lampén

Use two rand()'s.

$foo = rand(2);

if ($foo == 0)
rand(first_set);
else
rand(second_set);


Niklas

-Original Message-
From: Jeff Sittler [mailto:[EMAIL PROTECTED]] 
Sent: 14. maaliskuuta 2002 7:50
To: [EMAIL PROTECTED]
Subject: Re: [PHP] rand()


the min and max would work if I wanted the number between 33 and 146,
but I am wanting to specify two ranges, not just one.

Please RTFP

Jeff
"Jason Wong" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]...
> On Thursday 14 March 2002 13:31, Jeff Sittler wrote:
> > I am wanting to use rand() to generate a number between 33-90 OR
125-146.
> > Is there a way to do this?  I don't want any numbers before 33 or
between
> > 91-124 or after 146.  Could someone point me in the direction I need

> > to look to accomplish this.
>
> rand(min, max);
>
> Please RTFM.
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
>
> /*
> Man and wife make one fool.
> */



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] rand()

2002-03-13 Thread Rasmus Lerdorf

Just do the obvious:

$rand = rand(33,111);
$num = ($rand>90) ? $rand+35 : $rand;

On Wed, 13 Mar 2002, Jeff Sittler wrote:

> I am wanting to use rand() to generate a number between 33-90 OR  125-146.
> Is there a way to do this?  I don't want any numbers before 33 or between
> 91-124 or after 146.  Could someone point me in the direction I need to look
> to accomplish this.
>
> Thanks,
> Jeff
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] rand()

2002-03-13 Thread Jeff Sittler

the min and max would work if I wanted the number between 33 and 146, but I
am wanting to specify two ranges, not just one.

Please RTFP

Jeff
"Jason Wong" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]...
> On Thursday 14 March 2002 13:31, Jeff Sittler wrote:
> > I am wanting to use rand() to generate a number between 33-90 OR
125-146.
> > Is there a way to do this?  I don't want any numbers before 33 or
between
> > 91-124 or after 146.  Could someone point me in the direction I need to
> > look to accomplish this.
>
> rand(min, max);
>
> Please RTFM.
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
>
> /*
> Man and wife make one fool.
> */



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] rand()

2002-03-13 Thread Martin Towell

$n = rand(33, 112);
if ($n > 90)  $n += 34;

not tested in code, but logically, this should work

Martin

-Original Message-
From: Jeff Sittler [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 14, 2002 4:31 PM
To: [EMAIL PROTECTED]
Subject: [PHP] rand()


I am wanting to use rand() to generate a number between 33-90 OR  125-146.
Is there a way to do this?  I don't want any numbers before 33 or between
91-124 or after 146.  Could someone point me in the direction I need to look
to accomplish this.

Thanks,
Jeff



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] rand()

2002-03-13 Thread Demitrious S. Kelly

And I just realized how redundant the checks for less then and grater
then the rand min and rand max are...

Oh well... I'm tired :)

-Original Message-
From: Demitrious S. Kelly [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, March 13, 2002 9:45 PM
To: 'Jeff Sittler'; [EMAIL PROTECTED]
Subject: RE: [PHP] rand()

Something to the effect of

$num=0;
do {
$num=rand(33,146);
if ( $num > 90 && $num < 125 ) {
$num=0;
} else if ( $num > 146 || $num < 33 ) {
$num=0;
} 
} while ( $num == 0 );
 

note: ths is just off the top of my head... check for validity and
syntax.
-Original Message-
From: Jeff Sittler [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, March 13, 2002 9:31 PM
To: [EMAIL PROTECTED]
Subject: [PHP] rand()

I am wanting to use rand() to generate a number between 33-90 OR
125-146.
Is there a way to do this?  I don't want any numbers before 33 or
between
91-124 or after 146.  Could someone point me in the direction I need to
look
to accomplish this.

Thanks,
Jeff



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] rand()

2002-03-13 Thread Demitrious S. Kelly

Something to the effect of

$num=0;
do {
$num=rand(33,146);
if ( $num > 90 && $num < 125 ) {
$num=0;
} else if ( $num > 146 || $num < 33 ) {
$num=0;
} 
} while ( $num == 0 );
 

note: ths is just off the top of my head... check for validity and
syntax.
-Original Message-
From: Jeff Sittler [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, March 13, 2002 9:31 PM
To: [EMAIL PROTECTED]
Subject: [PHP] rand()

I am wanting to use rand() to generate a number between 33-90 OR
125-146.
Is there a way to do this?  I don't want any numbers before 33 or
between
91-124 or after 146.  Could someone point me in the direction I need to
look
to accomplish this.

Thanks,
Jeff



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] rand()

2002-03-13 Thread Jason Wong

On Thursday 14 March 2002 13:31, Jeff Sittler wrote:
> I am wanting to use rand() to generate a number between 33-90 OR  125-146.
> Is there a way to do this?  I don't want any numbers before 33 or between
> 91-124 or after 146.  Could someone point me in the direction I need to
> look to accomplish this.

rand(min, max);

Please RTFM.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
Man and wife make one fool.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Rand function

2002-01-22 Thread Jon Haworth

> Can anyone tell me why, when I run this
> $number = rand (1,12);
> The only number that ever appears is 5?
> Not really a random number...

You need to seed the random number generator first.

http://www.php.net/srand

HTH
Jon

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Rand function

2002-01-22 Thread Jason Wong

On Tuesday 22 January 2002 18:52, Sam wrote:
> Hi all,
>
> Can anyone tell me why, when I run this
>
> $number = rand (1,12);
> The only number that ever appears is 5?
> Not really a random number...


You need to seed the random number generator using srand(). Best to read the 
online annotated manual as there's some useful info regarding random number 
generation.

Remember you only need to call srand() *ONCE* during the lifetime of your php 
script. Do NOT call srand() each time you want a random number.


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
Now hatred is by far the longest pleasure;
Men love in haste, but they detest at leisure.
-- George Gordon, Lord Byron, "Don Juan"
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] rand(), mt_rand(), and my inability to make either of them random.

2001-01-26 Thread April

lol, nm, you weren't.  Why does it return Warning: Use of undefined constant
U - assumed 'U' in c:\apache\htdocs\temp\random.php on line 4 if I don't use
quotes, though?

ayway, I'm going to give up on this.  Thanks, though.
- Original Message -
From: "April" <[EMAIL PROTECTED]>
To: "Robert Collins" <[EMAIL PROTECTED]>; "PHP General"
<[EMAIL PROTECTED]>
Sent: Friday, January 26, 2001 3:15 PM
Subject: Re: [PHP] rand(), mt_rand(), and my inability to make either of
them random.


> Thanks.  It doesn't need to be completely random, just, more random than
> "1".  The occasional 3 would be enough for me.
>
> And,t hank you very very much.  You forgot the quotes around the U, btw.
> *huggss*
>
> - Original Message -
> From: "Robert Collins" <[EMAIL PROTECTED]>
> To: "'April'" <[EMAIL PROTECTED]>; "PHP General"
> <[EMAIL PROTECTED]>
> Sent: Friday, January 26, 2001 2:58 PM
> Subject: RE: [PHP] rand(), mt_rand(), and my inability to make either of
> them random.
>
>
> > this is a function that I wrote to solve this problem, but it is almost
> > impossible to get a truly random number you can get somthing pretty
close
> by
> > seeding with somthing like the time function, using the seconds since
> epoch
> > and this should be hard to duplicate.
> >
> >  > function random_number($config, $lownum, $highnum){
> >
> > $time = date(U);
> > $seed = srand($time);
> > $rand = rand($lownum, $highnum);
> >
> > echo  " > COLOR=\"$fontcolor\">$rand";
> >
> > $lownum  = "1";
> > $highnum = "100";
> > random_number("config.inc.php", $lownum, $highnum);
> >
> > }
> > ?>
> >
> > -Original Message-
> > From: April [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, January 26, 2001 1:50 PM
> > To: PHP General
> > Subject: [PHP] rand(), mt_rand(), and my inability to make either of
> > them random.
> >
> >
> > I have this scriptlet:
> >
> > $items = 6;
> > $randnum = rand(1,$items);
> > echo $randnum . "";
> >
> > Always, no matter how many times I hit refresh, it'll always return the
> > lowest possible value, in this case 1.  If I have rand(4,$items), it
> returns
> > four.
> >
> > So I tried mt_rand(), with this:
> >
> > $items = 6;
> > $randnum = mt_rand(1,$items);
> > echo $randnum . "";
> >
> > This always, without fail, returns the highest possible value.  6 in
this
> > case.
> >
> > I'm using Apache/4.0.3pl1 on Windows 2000, locally, just to develop.
> Could
> > this be a cache type problem?  Could the gods be conspiring to drive me
> > steadily insane?
> >
> > April
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] rand(), mt_rand(), and my inability to make either of them random.

2001-01-26 Thread April

Thanks.  It doesn't need to be completely random, just, more random than
"1".  The occasional 3 would be enough for me.

And,t hank you very very much.  You forgot the quotes around the U, btw.
*huggss*

- Original Message -
From: "Robert Collins" <[EMAIL PROTECTED]>
To: "'April'" <[EMAIL PROTECTED]>; "PHP General"
<[EMAIL PROTECTED]>
Sent: Friday, January 26, 2001 2:58 PM
Subject: RE: [PHP] rand(), mt_rand(), and my inability to make either of
them random.


> this is a function that I wrote to solve this problem, but it is almost
> impossible to get a truly random number you can get somthing pretty close
by
> seeding with somthing like the time function, using the seconds since
epoch
> and this should be hard to duplicate.
>
>  function random_number($config, $lownum, $highnum){
>
> $time = date(U);
> $seed = srand($time);
> $rand = rand($lownum, $highnum);
>
> echo  " COLOR=\"$fontcolor\">$rand";
>
> $lownum  = "1";
> $highnum = "100";
> random_number("config.inc.php", $lownum, $highnum);
>
> }
> ?>
>
> -Original Message-
> From: April [mailto:[EMAIL PROTECTED]]
> Sent: Friday, January 26, 2001 1:50 PM
> To: PHP General
> Subject: [PHP] rand(), mt_rand(), and my inability to make either of
> them random.
>
>
> I have this scriptlet:
>
> $items = 6;
> $randnum = rand(1,$items);
> echo $randnum . "";
>
> Always, no matter how many times I hit refresh, it'll always return the
> lowest possible value, in this case 1.  If I have rand(4,$items), it
returns
> four.
>
> So I tried mt_rand(), with this:
>
> $items = 6;
> $randnum = mt_rand(1,$items);
> echo $randnum . "";
>
> This always, without fail, returns the highest possible value.  6 in this
> case.
>
> I'm using Apache/4.0.3pl1 on Windows 2000, locally, just to develop.
Could
> this be a cache type problem?  Could the gods be conspiring to drive me
> steadily insane?
>
> April
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] rand(), mt_rand(), and my inability to make either of themrandom.

2001-01-26 Thread Philip Olson

Hi April,

You need to plant seeds to reach this goal, it discusses this in manual   
under rand() and mt_rand() so have a look here :

http://www.php.net/manual/en/function.rand.php

Which links to and talks about srand :

http://www.php.net/manual/en/function.srand.php

A seedless rand() is essentially useless.  Examples exist in the above,   
check out the user comments.

Philip

On Fri, 26 Jan 2001, April wrote:

> I have this scriptlet:
> 
> $items = 6;
> $randnum = rand(1,$items);
> echo $randnum . "";
> 
> Always, no matter how many times I hit refresh, it'll always return the
> lowest possible value, in this case 1.  If I have rand(4,$items), it returns
> four.
> 
> So I tried mt_rand(), with this:
> 
> $items = 6;
> $randnum = mt_rand(1,$items);
> echo $randnum . "";
> 
> This always, without fail, returns the highest possible value.  6 in this
> case.
> 
> I'm using Apache/4.0.3pl1 on Windows 2000, locally, just to develop.  Could
> this be a cache type problem?  Could the gods be conspiring to drive me
> steadily insane?
> 
> April
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] rand(), mt_rand(), and my inability to make either of them random.

2001-01-26 Thread Robert Collins

this is a function that I wrote to solve this problem, but it is almost
impossible to get a truly random number you can get somthing pretty close by
seeding with somthing like the time function, using the seconds since epoch
and this should be hard to duplicate.

$rand";

$lownum  = "1";
$highnum = "100";
random_number("config.inc.php", $lownum, $highnum);

}
?>

-Original Message-
From: April [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 26, 2001 1:50 PM
To: PHP General
Subject: [PHP] rand(), mt_rand(), and my inability to make either of
them random.


I have this scriptlet:

$items = 6;
$randnum = rand(1,$items);
echo $randnum . "";

Always, no matter how many times I hit refresh, it'll always return the
lowest possible value, in this case 1.  If I have rand(4,$items), it returns
four.

So I tried mt_rand(), with this:

$items = 6;
$randnum = mt_rand(1,$items);
echo $randnum . "";

This always, without fail, returns the highest possible value.  6 in this
case.

I'm using Apache/4.0.3pl1 on Windows 2000, locally, just to develop.  Could
this be a cache type problem?  Could the gods be conspiring to drive me
steadily insane?

April


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



RE: [PHP] rand is not random for me :(

2001-01-10 Thread James Atkinson

Did you seed your random number generator?

ie: srand ((double) microtime() * 100);

- James

> -Original Message-
> From: Brandon Orther [mailto:[EMAIL PROTECTED]]
> Sent: January 10, 2000 2:24 PM
> To: PHP User Group
> Subject: [PHP] rand is not random for me :(
> 
> 
> When I use random rand(1, 10) I always get 2?
> 
> Thank you,
> 
> 
> Brandon Orther
> WebIntellects Design/Development Manager
> [EMAIL PROTECTED]
> 800-994-6364
> www.webintellects.com
>  
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] rand is not random for me :(

2001-01-10 Thread Web Master

you have generate a unique seed to generate random number srand, please read

http://www.php.net/manual/function.rand.php

has more info

Brandon Orther wrote:

> When I use random rand(1, 10) I always get 2?
>
> Thank you,
>
> 
> Brandon Orther
> WebIntellects Design/Development Manager
> [EMAIL PROTECTED]
> 800-994-6364
> www.webintellects.com
> 
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]