Home / Software / Computer programming / Displaying the same random array in more than one location
0 Members and 2 Guests are viewing this topic. « previous next »
Pages: [1] - (Bottom) Print
Author Topic: Displaying the same random array in more than one location  (Read 146 times)
jonsan32
Topic Starter
Rookie



Posts: 27




« on: February 02, 2012, 09:44:39 AM »


Can I display a random array in more than one spot with random results? Or maybe a better way of asking (maybe not) is Can I echo an array without the use of php?

Simple question, I'll take NO for an answer if it's not possible.

With a random array, can I display the results multiple time on the same page. I know I can't use css, and I would rather not use php... but is there a way for me to list the script below, then just punch in a div class at several points throughout my site?

I'm using this for advertising, and I'd like to be able to display the random image and link at 10 different points on the same page. Then to edit, I'd only want to edit the one single source. I guess it would kinda be like a slot machine, and I wouldn't mind a situation where they'd all end up as the same image :-)

Any help would be great. Thanks.


JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script type="text/javascript">
 
//Javascript Created by Computerhope http://www.computerhope.com
 
//store the quotations in arrays
 
var images = [],
index = 0;
 
images[0] = "<a href = 'http://www.computerhope.com/index.htm'><img src='http://www.computerhope.com/banners/banner.gif' alt='Visit Computer Hope'>[/url]";
 
images[1] = "<a href = 'http://www.computerhope.com/history/index.htm'><img src='http://www.computerhope.com/banners/banner2.gif' alt='Computer History'>[/url]";
 
images[2] = "<a href = 'http://www.computerhope.com/index.htm'><img src='http://www.computerhope.com/banners/banner3.gif' alt='Visit Computer Hope'>[/url]";
 
images[3] = "<a href = 'http://www.computerhope.com/newslet.htm'><img src='http://www.computerhope.com/banners/banner4.gif' alt='Computer Hope Newsletter'>[/url]";
 
index = Math.floor(Math.random() * images.length);
 
document.write(images[index]);
 
//done
 
</script>
IP logged

If you only have a hammer, you tend to see every problem as a nail. I some times see my computer as a nail.
bwilcutt
Greenhorn



Posts: 5

Certifications: List
Experience: Guru
OS: Unknown

Curious Internet
« Reply #1 on: February 16, 2012, 04:05:35 PM »

What you are looking for is a random scatter algorith, commonly used in graphics as a "digital disolve" algorith.

Microcornacopia posted such an algorithm back in the 80's.  You can find them on the internet is you google "digital dissolve".  Here's a link to one:
http://cd.textfiles.com/graphics16000/GENERAL/GEMS/G_GEMSI.TXT

The idea behind the algorithm is to "appear" random [although it is not], giving you X number of points in what looks random, but does not repeat.
IP logged

Dr. Bryan Wilcutt, DC.S.
Pages: [1] - (Top) Print 
Home / Software / Computer programming / Displaying the same random array in more than one location « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.106 seconds with 19 queries.