How to Start Youtube Playlist from Random Video

If you want to start a Youtube playlist from random video, just add: &index=random_number to the src attribute of the embed code.

The code

To produce a random number, I use php rand. Something like

        print rand(1,9)

(replace “9” with the count of your playlist videos).

Example

Here is an example of embed code:

<iframe width="853"
                height="480"
                src="//www.youtube.com/embed/videoseries?list=PLSsDdmdvvvGep2WaKOSPQe2jubDvtLblk&index=<?php print rand(1,9)?>"
                frameborder="0"
                allowfullscreen></iframe>