Home »
Imported messages »
comp.lang.php »
Shuffle problem
|
|
|
|
|
Re: Shuffle problem [message #182999 is a reply to message #172196] |
Wed, 02 October 2013 02:02  |
Lew Pitcher
Messages: 60 Registered: April 2013
Karma: 0
|
Member |
|
|
On Monday 30 September 2013 03:26, in comp.lang.php, "richard"
<noreply(at)example(dot)com> wrote:
> On my site I want to create a play list that is randomly selected when the
> page is loaded.
> I have ten tables, each with 100 rows.
> I want to extract the first 20 rows from each table.
> Then shuffle that and create the list.
> Somehting similar to shuffling a deck of cards.
>
> So that my playlist might look like:
>
> 1965 #4
> 1963 #13
> 1969 #18
> 1961 #10
> 1960 #3
>
> What ways can I do this?
$numbers = range(1, 200);
shuffle($numbers);
foreach ($numbers as $number)
{
$seq = $number % 20;
$year = 1950 + floor($number / 20);
printf("%4u #%d<br/>",$year,$seq);
}
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
|
|
|
Goto Forum:
Current Time: Thu Apr 10 17:31:27 GMT 2025
Total time taken to generate the page: 0.06912 seconds