Non-repeating random array

    Date: 08/08/07 (Javascript Community)    Keywords: no keywords


    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/



    
    



    I know the while condition is messed up. It seems as if the length of the array RandStore does not update for the comparison. Thats why there is a nested escape. I want the loop to continue until all the values in HomeImage are used.

    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.

    Source: http://community.livejournal.com/javascript/138134.html

« Confirm boxes || Randomize Array »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home