473,385 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Random quote help

I'm using the following to generate a random quote on a PHP page and it
works fine:

<?php
$quotes[] = 'quote #1';
$quotes[] = 'quote #2';
$quotes[] = 'quote #3';
$quotes[] = 'etc...';

srand ((double) microtime() * 1000000);
$random_number = rand(0,count($quotes)-1);

echo ($quotes[$random_number]);
?>
My question is how can I modify this so that it would show a single
quote but only every 10th time the page was called? I searched Google to
see if there was a premade script that would do this but all I could
find were ones like I'm already using.

Thanks.

Jul 16 '05 #1
2 2415
JDJones wrote:
I'm using the following to generate a random quote on a PHP page and
it works fine:

<?php
$quotes[] = 'quote #1';
$quotes[] = 'quote #2';
$quotes[] = 'quote #3';
$quotes[] = 'etc...';

srand ((double) microtime() * 1000000);
$random_number = rand(0,count($quotes)-1);

echo ($quotes[$random_number]);

My question is how can I modify this so that it would show a single
quote but only every 10th time the page was called? I searched Google
to see if there was a premade script that would do this but all I
could find were ones like I'm already using.


If you want this random you can simply use rand(0,9) == 0 or so, if you
want it to be exactly every 10th time you need to write to a text file
or a database. A quite simple task using fopen(), fwrite(), fread() etc.
Per Gustafsson

--
http://www.pergustafsson.com/
Jul 16 '05 #2

"JDJones" <wv***@netscape.net> wrote in message
news:be**********@slb3.atl.mindspring.net...
I'm using the following to generate a random quote on a PHP page and it
works fine:

<?php
$quotes[] = 'quote #1';
$quotes[] = 'quote #2';
$quotes[] = 'quote #3';
$quotes[] = 'etc...';

srand ((double) microtime() * 1000000);
$random_number = rand(0,count($quotes)-1);

echo ($quotes[$random_number]);
?>
My question is how can I modify this so that it would show a single
quote but only every 10th time the page was called? I searched Google to
see if there was a premade script that would do this but all I could
find were ones like I'm already using.

Thanks.


I suggest a cookie or session or keeping track in a file if you want it
exactly every ten times - if you're not bothered too bothered, you could
divide the hour by ten and if the current minute fits between one of two
values, use that to make your selection - that way a page refresh would
pretty much get you the same value unless the user kept refreshing for
longer than six minutes...

Jul 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Boris Borcic | last post by:
does x.sort(cmp = lambda x,y : cmp(random.random(),0.5)) pick a random shuffle of x with uniform distribution ? Intuitively, assuming list.sort() does a minimal number of comparisons to ...
4
by: eltower | last post by:
Hey all, I'm trying to write a program in Python for learning purposes which is meant to: Generate a random number from 0 to 6 Insert this random number to the end of a list unless the number...
3
by: clsmith66 | last post by:
I'm hoping someone can help me with a problem I'm having using the random class. I need to return a "random" number between 0 and 15, so i did this Dim r as new Random() Return r.Next(0, 15) ...
11
by: Kevin Williamson | last post by:
Hi, I've written a lottery programme in PHP that selects 10 winners a week from approximately 18,000 shares. The problem I have is that of the ten winners one week the same share number was...
7
by: alphaLaura | last post by:
Hi all - I'm just new to the group and I hope nobody minds me asking for some help. I currently have an assignment which deals with matrices (more specifically, Gauss-Seidel solving of...
5
by: Christo | last post by:
hello I am new to java very new and am hoping someone can offer me some help. I know that i need to use java.util.Random somewhere to generate a random number can anyone show me the code to...
20
by: jjmillertime | last post by:
I'm new so i apologize if this is in the wrong spot. I'm also new to programming in C and i've been searching for quite a while on how to create a program using C that will generate two random...
12
by: Juha Nieminen | last post by:
I'm trying to use a random number generator and rand() is just not up to the task (RAND_MAX is way too small). I searched in the help system and found the System::Random class which seems to be...
6
by: Mike Langworthy | last post by:
i can not seem to get this code to work. someone please help using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program {
15
by: caca | last post by:
Hello, This is a question for the best method (in terms of performance only) to choose a random element from a list among those that satisfy a certain property. This is the setting: I need to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.