1. ## array(question)

Hey all

I have a small array question for ya!

I have an array of five things. I generate a random number and use it to pull out one of the five things in the list.

BUT! What if I wanted to use that random number to create a STARTING POINT in an array. In other words to,say, print a list of the array with the first element in the list decided by the random number.

example:

arr[0]
arr[1]
arr[2]
arr[3]
arr[4]

random number is 3, so I want to then print

arr[2]
arr[3]
arr[4]
arr[0]
arr[1]

Does anybody have any idea how I can do this?

Cheers

azz

2. ## Re: array(question)

can't you just create a processing script ie something like this

function printInOrder(theArray)
{
int a = rand(5); --> I dunno the syntax for using rand.. but you get the idea, put the rand number in a variable
int b = 0; //Counter
int c = (put array size here); //Num of items in array
while(b < c)
{
//pseudocode below, have to figure out syntax
if b+a >= arraySize
print theArray[b+a - arraySize]
else
print theArray[b+a]
counter++
}
}

sorry it's a bit messy. dunno if it answers your question or not ?

dr
Originally posted by azzkika
Hey all

I have a small array question for ya!

I have an array of five things. I generate a random number and use it to pull out one of the five things in the list.

BUT! What if I wanted to use that random number to create a STARTING POINT in an array. In other words to,say, print a list of the array with the first element in the list decided by the random number.

example:

arr[0]
arr[1]
arr[2]
arr[3]
arr[4]

random number is 3, so I want to then print

arr[2]
arr[3]
arr[4]
arr[0]
arr[1]

Does anybody have any idea how I can do this?

Cheers

azz

3. DUDE! You're the man!

Yep, that works nicely. If you want, here's the full code I used. It gets quite scary but the logic is PERFECT. Thanks mate!

<% function showPic(){ Response.Write(this.pic); }
function showText(){ Response.Write(this.text); }
function showTitle(){ Response.Write(this.title); }

{ this.pic = pic;
this.text = text;
this.title = title;

this.showPic = showPic;
this.showText = showText;
this.showTitle = showTitle; }

var counter = 0;
var ArraySize = 3; %>

<table width="100%" border="1" cellspacing="15" cellpadding="0" class="content">

<% while (counter < ArraySize)
{ thePosition = (counter+AdRandom) - ArraySize %>
<tr>
</tr>
<% }
else {
<tr>
</tr>
<% }
counter++ } %>

</table>

kinda funky, huh!

Thanks again

azz

4. Glad to be of help

dr

5. I wrote a method for re-ordering arrays like that...just FYI
Code:
```Array.prototype.reOrder = function( i )
{
return this.concat( this.splice( 0, i ) );
}```
Should work with most versions of Netscape and IE 5.5+

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•