Solved

multiple, non-duplicating random image loads

Posted on 1998-03-30
2
220 Views
Last Modified: 2011-10-03
I'm looking to set up a 5 x 5  matrix of images which I would like scrambled every time the page is loaded. I know how to create a random number in JavaScript and use that number to load a numbered gif, such as 1.gif 2.gif, etc. But how would I generate a random loading scheme which will exclude any of the random numbers I've already used?  In other words,  I have 25 images and I want them to load in random order, with equal chance to be in any position in the matrix and not always next to the same other images. Does anyone know how to do that with JavaScript?
0
Comment
Question by:bheerman
2 Comments
 
LVL 3

Accepted Solution

by:
percyn earned 200 total points
ID: 1278939
I guess what you really want to do is randomize the order of an exclusive list of images. Thus you have to maintain a temp array of "already selected numbers" and check against this array for every selection.

You will end up with a double nested for loop with a if statement in it.
0
 

Author Comment

by:bheerman
ID: 1278940
I'm not good enough to complete the script without more help.

What I would really like is a pre-written script that generates a set of non-recurring integers, in my case from 1 to 25, in a scrambled order upon each trigger. I've given up at the point outlined below. (The image tags are for outline purposes, I'm really only stuck on the JavaScript.)

<!-- This document was created with HomeSite 2.5 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<HTML>
<HEAD>
      <TITLE>Bingo Test</TITLE>
</HEAD>



<SCRIPT LANGUAGE="JavaScript">
<!--
var used = new Array()

if (used =

for(var i=1; i<=25;)


      image01 = ('"+Math.ceil(Math.random()*25) + ".gif")
      
      image02 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image03 = ('"+Math.ceil(Math.random()*25) + ".gif")      

      image04 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image05 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image06 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image07 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image08 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image09 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image10 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image11 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image12 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image13 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image14= ('"+Math.ceil(Math.random()*25) + ".gif")

      image15 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image16 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image17 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image18 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image19 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image20 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image21= ('"+Math.ceil(Math.random()*25) + ".gif")

      image22 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image23= ('"+Math.ceil(Math.random()*25) + ".gif")

      image24 = ('"+Math.ceil(Math.random()*25) + ".gif")

      image25 = ('"+Math.ceil(Math.random()*25) + ".gif")
      




//-->
</SCRIPT>

<BODY>

<TABLE Border="1">

<TR>
<TD>image 1</TD>
<TD>image 2</TD>
<TD>image 3</TD>
<TD>image 4</TD>
<TD>image 5</TD>
</TR>

<TR>
<TD>image 6</TD>
<TD>image 7</TD>
<TD>image 8</TD>
<TD>image 9</TD>
<TD>image 10</TD>
</TR>

<TR>
<TD>image 11</TD>
<TD>image 12</TD>
<TD>image 13</TD>
<TD>image 14</TD>
<TD>image 15</TD>
</TR>

<TR>
<TD>image 16</TD>
<TD>image 17</TD>
<TD>image 18</TD>
<TD>image 19</TD>
<TD>image 20</TD>
</TR>

<TR>
<TD>image 21</TD>
<TD>image 22</TD>
<TD>image 23</TD>
<TD>image 24</TD>
<TD>image 25</TD>
</TR>
</TABLE>



</BODY>
</HTML>

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question