Hi
you can use PHP rand() function for selecting a random number between 1 to
100.
http://www.senpai-it.com/dedicated_servers.php Senpai IT Solutions
Dedicated Server at low cost
WEISD wrote:
On a php web page I want to generate a random number between say 1 and 10
and then use that
On Thu, Nov 6, 2008 at 3:52 AM, Amisha_Sharma [EMAIL PROTECTED] wrote:
Hi
you can use PHP rand() function for selecting a random number between 1 to
100.
Amisha,
Welcome to the list, but please don't top post. For a list of all
the guidelines for the official PHP lists, including
On Thu, Nov 6, 2008 at 10:53 AM, WEISD [EMAIL PROTECTED] wrote:
Gary M. Josack [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Stephen wrote:
On a php web page I want to generate a random number between say 1 and
10 and then use that number to reference a particular file in
an
Gary M. Josack [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Stephen wrote:
On a php web page I want to generate a random number between say 1 and
10 and then use that number to reference a particular file in
an include tag.
?php include('GeneratedNumber.html'); ?
Is there an
[snip]
?php
$number = rand(1, 10);
include(footer$number.html); ?
You can see it in action here at the bottom of the page there is a
footer.
Each footer is the same right now except I have numbered them for
testing.
As I refresh the page, I get footer10 almost always with an occasional
2 or
On Thu, 11/6/08, WEISD [EMAIL PROTECTED] wrote:
That is strange. I get pretty balanced results on this
computer.
?php
$histogram = array_fill(1, 10, 0);
$iterations = 20;
for ($i = 0; $i $iterations; ++$i) {
++$histogram[round(rand(1, 10))];
}
WEISD wrote:
That is strange. I get pretty balanced results on this computer.
?php
$histogram = array_fill(1, 10, 0);
$iterations = 20;
for ($i = 0; $i $iterations; ++$i) {
++$histogram[round(rand(1, 10))];
}
print_r($histogram);
?
Andrew
Simple code,
?php
$number =
Computer functions to generate random numbers are not designed to do what
their name suggests.
Software testing requires repeatability, and this includes random number
generation.
Without knowing how PHP seeds the generator it is difficult to predict
what it will do.
I still think
That is strange. I get pretty balanced results on this computer.
?php
$histogram = array_fill(1, 10, 0);
$iterations = 20;
for ($i = 0; $i $iterations; ++$i) {
++$histogram[round(rand(1, 10))];
}
print_r($histogram);
?
Andrew
Simple code,
?php
$number = rand(1, 10);
WEISD wrote:
Computer functions to generate random numbers are not designed to do
what their name suggests.
Software testing requires repeatability, and this includes random
number generation.
Without knowing how PHP seeds the generator it is difficult to predict
what it will do.
I
WEISD wrote:
Computer functions to generate random numbers are not designed to do
what their name suggests.
Software testing requires repeatability, and this includes random
number generation.
Without knowing how PHP seeds the generator it is difficult to predict
what it will do.
I
At 10:30 AM -0600 11/6/08, WEISD wrote:
You can see it in action here at the bottom of the page there is a
footer. Each footer is the same right now except I have numbered
them for testing.
As I refresh the page, I get footer10 almost always with an
occasional 2 or 4 here and there...
http://www.weisd.com/store2/WINHD-9022.php
Not me -- I get a normal distribution.
Cheers,
tedd
Thanks Tedd, That is because it is using time now and not rand...
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Stephen wrote:
On Thu, 11/6/08, WEISD [EMAIL PROTECTED] wrote:
That is strange. I get pretty balanced results on this
computer.
?php
$histogram = array_fill(1, 10, 0);
$iterations = 20;
for ($i = 0; $i $iterations; ++$i) {
++$histogram[round(rand(1, 10))];
}
1. change the number to a string: $t = (string) time();
2. chop off the last char of the string: $char = substr($t, -1);
3. you're done...: include footer$char.html;
Time wins certainly produces better results, at least for what I am
doing, than rand...
Thanks all for your input...
At 11:35 AM -0600 11/6/08, WEISD wrote:
http://www.weisd.com/store2/WINHD-9022.php
Not me -- I get a normal distribution.
Cheers,
tedd
Thanks Tedd, That is because it is using time now and not rand...
Just as point of notice.
When I ask a question and provide a url, I keep the url
On a php web page I want to generate a random number
between say 1 and 10
and then use that number to reference a particular file in
an include tag.
?php include('GeneratedNumber.html'); ?
Is there an easy way to do this?
Get the time and use the last digit converting 0 to 10.
Here's how you generate a random number:
http://us.php.net/manual/en/function.rand.php
There are a number of things you can do with that to select a random file and
include it. Have an associative array where the random number matches an
array key and the value is the filename you want, is one
Just starting out, thanks.
So,
?php
$number = rand(1, 10);
include('$number.html'); ?
I should have prefaced the question with, New to PHP...
TG [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Here's how you generate a random number:
Stephen wrote:
On a php web page I want to generate a random number
between say 1 and 10
and then use that number to reference a particular file in
an include tag.
?php include('GeneratedNumber.html'); ?
Is there an easy way to do this?
Get the time and use the last digit converting 0
WEISD wrote:
Just starting out, thanks.
So,
?php
$number = rand(1, 10);
include('$number.html'); ?
I should have prefaced the question with, New to PHP...
TG [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Here's how you generate a random number:
Umm I must notify you, just in case you don't know this, that you have to be
aware of the fact that the humanity haven't found a way to get a random
number (yet. they are working on it while I'm writing this..) (;
On Wed, Nov 5, 2008 at 9:43 PM, Gary M. Josack [EMAIL PROTECTED] wrote:
WEISD
On Wed, 2008-11-05 at 12:41 -0600, WEISD wrote:
On a php web page I want to generate a random number between say 1 and 10
and then use that number to reference a particular file in an include tag.
?php include('GeneratedNumber.html'); ?
Is there an easy way to do this?
Thanks
Apologies, my mail client was supposed to line-wrap that for me
-
Hi,
I'm currently experiencing a problem with a phpBB board that appears
to be due to the way random number generation works in PHP. I have
posted on serveral phpBB boards and have received no answers, so I
think I need to
Gordon McKeown wrote:
Apologies, my mail client was supposed to line-wrap that for me
-
Hi,
I'm currently experiencing a problem with a phpBB board that appears
to be due to the way random number generation works in PHP. I have
posted on serveral phpBB boards and have received no answers,
Use a database query to verify the random number has not been used before.
$number_checker = 1;
while ($number_checker != 0){
#insert your $random_number code
$query = SELECT COUNT(*) AS total FROM some_table WHERE
random_number_field = '$random_number';
$result =
Many thanks Thomas and Maciek. I'll try removing mt_srand to start with,
and if that doesn't work out I'll put in the uniqueness check.
Cheers,
Gordon.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
http://www.php.net/manual/en/function.array-rand.php
At 11:35 18-12-02 +, shaun wrote:
Hi,
Say i have a set of non sequential numbers for example: 1 3 8 12 13 16 19
21.
How can i get php to take a random number from this set?
Thanks for your help
--
PHP General Mailing List
Hi shaun,
Store all those numbers in an array and use the function
array_rand.
On Wed, 18 Dec 2002, shaun wrote:
Hi,
Say i have a set of non sequential numbers for example: 1 3 8 12 13 16 19
21.
How can i get php to take a random number from this set?
Thanks for
$guess = = $number
is wrong.
You should write:
$guess == $number
Regards,
Hiroshi Ayukawa
http://hoover.ktplan.ne.jp/kaihatsu/php_en/index.php?type=top
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Try Now:
form action=number.php method=post
The computer has picked a number between 1 and 10. Guess the number and
you win!BR
Enter your guess:
input type=text name=guess value= size=3
INPUT TYPE=submit VALUE=Submit my number NAME=submit /form
-Original Message-
From: Jennifer Downey
On Saturday 13 March 2010 11:54, Jennifer Downey wrote:
Hi all,
I having a hard time understanding why this won't work. I have a form which
is suppose to pass the guess to the script. Here it is:
It's no good just telling us it doesn't work. You need to tell us what
happens when you run it.
Use this function, the $num argument, is the total
of numbers. Ex: if $num is 5, the funtion will return
56743, is five numbers.
function random($num)
{
srand ((double) microtime() * 100);
$temp = rand().rand().rand();
$temp = substr($temp, 0, $num);
return $temp;
} //fim function
Come on - you haven't even bothered to check the manual. Search for this at
php.net
Miles
At 03:09 PM 5/18/01 -0400, Daniel Coronel wrote:
Hi!
I need to really generate a random number in a function but not like doing
it.
Somebody could help me. Thanks.
Daniel Coronel.
--
PHP General
i love when newbies ask for help and i'm able to help,
but when it comes to people being just plain lazy,
i agree with Miles...
** please read the docs before asking questions **
-Original Message-
From: Miles Thompson [mailto:[EMAIL PROTECTED]]
Subject: Re: [PHP] Random number
If you need just plain random number generator check manual. If you want a
true pseudo-random number generator you may want to check:
http://www.ulib.org/webRoot/Books/Numerical_Recipes/bookcpdf.html
Those generators used in scientific calculations where true reproducible and
low correlated
why not use the rand() ?
manual says:
rand -- Generate a random value
Description
int rand ([int min [, int max]])
If called without the optional min, max arguments rand() returns a
pseudo-random value between 0 and RAND_MAX. If you want a random number
between 5 and 15 (inclusive), for
Wotcha Tris :-)
Try this:
mt_srand((double)microtime()*100);
$my_random_number = mt_rand(1, 20);
HTH
Jon
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]
Sent: 02 May 2001 12:07
To: [EMAIL PROTECTED]
Subject: [PHP] Random number generation...
Hi there,
A
?php
srand((double)microtime()*100);
$number = rand(1,20);
echo $number;
?
Regards,
Avetis
[EMAIL PROTECTED] wrote:
Hi there,
A potentially dumb question here.
Is there an easy way to display a random number between 1 and 20?
I have looked on line, but either I am looking inall teh
The manual also says:
mt_rand -- Generate a better random value
I've been using mt_rand() over rand() every time - is there any reason not
to?
Cheers
Jon
-Original Message-
From: elias [mailto:[EMAIL PROTECTED]]
Sent: 03 May 2001 00:05
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Random
mt_rand -- Generate a better random value
I've been using mt_rand() over rand() every time - is there any reason not
to?
Cheers
Jon
-Original Message-
From: elias [mailto:[EMAIL PROTECTED]]
Sent: 03 May 2001 00:05
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Random number ge
41 matches
Mail list logo