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

Home » Imported messages » comp.lang.php » Shuffle problem
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Shuffle problem [message #182999 is a reply to message #172196] Wed, 02 October 2013 02:02 Go to previous message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma:
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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Help with Security
Next Topic: configuration problem rsyslog with php
Goto Forum:
  

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

Current Time: Sun Nov 24 21:19:41 GMT 2024

Total time taken to generate the page: 0.05063 seconds