Top.Mail.Ru
? ?
Javascript's Journal
 
[Most Recent Entries] [Calendar View] [Friends View]

Tuesday, August 7th, 2007

Time Event
6:07p
Non-repeating random array

I wrote a script for a client's site to display a set of images randomly - without repeating an image.

I found a useful "if it exists in array" object here (and other useful method-objects):
http://www.svendtofte.com/code/usefull_prototypes/

scriptCollapse ) Here's a sample output. The number in the bracket indicates the index being stored/used.
    HomeImage length: 4 RandStore length: 0

    HomeImage length: 4 RandStore length: 0 index: 0 [0]

    HomeImage length: 4 RandStore length: 1 index: 0

    HomeImage length: 4 RandStore length: 1 index: 2 [2]

    HomeImage length: 4 RandStore length: 2 index: 3 [3]

    HomeImage length: 4 RandStore length: 3 index: 0

    HomeImage length: 4 RandStore length: 3 index: 1 [1]
    HomeImage length: 4 RandStore length: 4
You could use this script to simulate dealing cards from a single deck.

<< Previous Day 2007/08/07
[Calendar]
Next Day >>
About LiveJournal.com
Image