Re: Lots of 2s



In message <62g0j3F234nqvU1@xxxxxxxxxxxxxxxxxx>, Willy Eckerslyke <oss108no_spam@xxxxxxxxxxxx> writes:
Sam Nelson wrote:

You could try replacing $imageNumber = time() % count($fileList);
with
$imageNumber = rand(0.89)

Or indeed:
$imageNumber = rand(1,(count($fileList)))

If you could be bothered, I'd be tempted to keep track of the images you've already used (just by number, if that's easiest), so that you don't re-use them until you've done them all. That's annoying to do in PHP, as you'd need to pass state back and forth, though easy with a little JavaScript.

Client-side, have an array of all the images you can see. Shuffle the array, go through it one by one with a counter. Timeout with a delay between changes. When you get to the end of the array, shuffle again and put the array counter back to zero. Your PHP could construct the array for the JavaScript code, and drop it into the web page.

I've tended to find that people are happier with this sort of approach than just pure randomness - everything will get seen within a finite (and fairly short) amount of time.

--
The Massive Continuity of Ducks
.



Relevant Pages

  • Re: OT Camera Raw 5.2 and Photoshop CS4, not CS3
    ... used at the loop boundaries. ... will lay out an array in memory. ... But if the the compiler sets the array in memory as 8 blocks of 6 reals, ... Instead it can be quite slow on large images. ...
    (rec.photo.digital.slr-systems)
  • Re: Preload images
    ... Now there is only one array of images which looks ... Avoid global variables. ... Prototype.js was written by people who don't know javascript for people ...
    (comp.lang.javascript)
  • Re: help with arrays
    ... The tags you found so confusing are in fact, ... JavaScript, but they are variant objects, and do not support ... looks like what it's doing is using an array of images, ... images, and a button which invokes a JS function which simply uses setInterval to cycle through the images. ...
    (microsoft.public.frontpage.programming)
  • Re: javaScript and Ajax - IE7
    ... That's positive as all of the images should be in the document. ... That's worse than using an array. ...   getTransport: function{ ... some code someone has written in javaScript which includes some ...
    (comp.lang.javascript)
  • Re: Photo gallery
    ... but now I can at least show photos when a link are created. ... Instead of allowing the user from outside give you the image name, they give you the array cell number. ... // View images when the links are clicked ... Now you check first if the get variables are set or not, then you compare the values of the cells in the GET array. ...
    (alt.php)