473,569 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

random number generation

How do I add random number generation to this background image slide
show? Everything I try kills if. TIA
_______________ _______________ _______
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="GENERATOR " content="Micros oft FrontPage 4.0">
<meta name="ProgId" content="FrontP age.Editor.Docu ment">
<title>New Page 2</title>
</head>
<body>
<SCRIPT LANGUAGE="JavaS cript1.2">
var pic=new Array()
pic[0]="pic/./000.bmp"
pic[1]="pic/./001.jpg"
pic[2]="pic/./002.jpg"
pic[3]="pic/./003.jpg"
pic[4]="pic/./004.jpg"
pic[5]="pic/./005.jpg"
pic[6]="pic/./006.jpg"
pic[7]="pic/./007.jpg"
pic[8]="pic/./008.jpg"
pic[9]="pic/./009.jpg"
var img=new Array()
for (i=0;i<pic.leng th;i++){
img[i]=new Image()
img[i].src=pic[i]
}
var enf=-1
function Slide(){
if (enf<pic.length-1)
enf++
else
enf=0
document.body.b ackground=img[enf].src
}
if (document.all|| document.getEle mentById)
window.onload=n ew Function('setIn terval("Slide() ",1000)')
</SCRIPT></BODY></HTML>
Sep 10 '08 #1
6 1718
Fan924 wrote:
How do I add random number generation to this background image slide
show? Everything I try kills if. TIA
[...]
var enf=-1
function Slide(){
if (enf<pic.length-1)
enf++
else
enf=0
document.body.b ackground=img[enf].src
}
You should try to learn how to write legible code first. After that it
should become much easier for you to see the issue.

However, as you are using FrontPage 4.0 and all other kinds of obsolete,
error-prone, inefficient nonsense, and all of this could already be
copy-and-pray in the first place, you may already be beyond help.

<http://jibbering.com/faq/>
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Sep 10 '08 #2
Fan924 meinte:
How do I add random number generation to this background image slide
show? Everything I try kills if. TIA
would be something like

i = parseInt(Math.r andom() * pic.length, 10);

Perhaps you should show what you'e tried so far. However, given the
Frontpage crap you've posted, I can't think of anything meaningful.

["JS" atrocities snipped]

Gregor

--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Sep 10 '08 #3
Fan924 wrote:
How do I add random number generation to this background image slide
show? Everything I try kills if. TIA
_______________ _______________ _______
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="GENERATOR " content="Micros oft FrontPage 4.0">
<meta name="ProgId" content="FrontP age.Editor.Docu ment">
<title>New Page 2</title>
</head>
<body>
<SCRIPT LANGUAGE="JavaS cript1.2">
The language attribute was deprecated many years ago, type is reqired, use:

<script type="text/javascript">
Indented code is easier to read for most of us.

var pic=new Array()
pic[0]="pic/./000.bmp"
pic[1]="pic/./001.jpg"
pic[2]="pic/./002.jpg"
pic[3]="pic/./003.jpg"
pic[4]="pic/./004.jpg"
pic[5]="pic/./005.jpg"
pic[6]="pic/./006.jpg"
pic[7]="pic/./007.jpg"
pic[8]="pic/./008.jpg"
pic[9]="pic/./009.jpg"
That can be written more concisely as an Array literal:

var pic = ["pic/./000.bmp", "pic/./001.jpg",
"pic/./002.jpg", "pic/./003.jpg",
...
];

var img=new Array()
var img = [];

for (i=0;i<pic.leng th;i++){
Don't forget to declare variables. It doesn't really matter here but is
a good habbit:

for (var i=0; i<pic.length; i++){

img[i]=new Image()
img[i].src=pic[i]
}
var enf=-1
I understand why you've used -1 here, but consider using 0 and setting
your background image to pic/./000.bmp otherwise your visitors will have
to wait for the entire page and all images to load, then another second
before any background image is shown. So use:

<body style="backgrou nd-image: url('pic/./000.bmp');">

function Slide(){
By convention, function names that start with capital letters are
reserved for constructors.
if (enf<pic.length-1)
enf++
else
enf=0
That can be written as:

var enf = 0;
function Slide() {
enf = ++enf % pic.length;

document.body.b ackground=img[enf].src
document.body.s tyle.background Image = 'url("'+img[enf].src+'")';

}
if (document.all|| document.getEle mentById)
The intention of feature detection is that you test for the feature that
you want to use. It is a bad strategy to test for some other feature to
infer support for the one you actually want to use.

window.onload=n ew Function('setIn terval("Slide() ",1000)')
The Function constructor is unnecessary here and equivalent to the use
of eval, use:

window.onload = function(){
window.setInter val(slide, 1000);
}
--
Rob
Sep 10 '08 #4
In comp.lang.javas cript message <sj************ *@nntpserver.sw ip.net>,
Wed, 10 Sep 2008 15:44:47, Gregor Kofler <us****@gregork ofler.at>
posted:
>Fan924 meinte:
>How do I add random number generation to this background image slide
show? Everything I try kills if. TIA

would be something like

i = parseInt(Math.r andom() * pic.length, 10);
Please read the standard about what parseInt is *for*, and the FAQ for
Random(). Granted the best answer is not unlike that, but why post
*that*.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, nr London UK. ?@merlyn.demon. co.uk IE7 FF2 Op9 Sf3
news:comp.lang. javascript FAQ <URL:http://www.jibbering.c om/faq/index.html>.
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 10 '08 #5
Dr J R Stockton meinte:
In comp.lang.javas cript message <sj************ *@nntpserver.sw ip.net>,
Wed, 10 Sep 2008 15:44:47, Gregor Kofler <us****@gregork ofler.at>
posted:
>i = parseInt(Math.r andom() * pic.length, 10);

Please read the standard about what parseInt is *for*, and the FAQ for
Random(). Granted the best answer is not unlike that, but why post
*that*.
Right doc - that's bullshit. Should have been Math.round() or rather
Math.floor() - in fact, that's what I use in my own library. Sorry.

Gregor
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Sep 10 '08 #6
On Wed, 10 Sep 2008 at 23:54:15, in comp.lang.javas cript, RobG wrote:
>Fan924 wrote:
>How do I add random number generation to this background image slide
show? Everything I try kills if. TIA
______________ _______________ ________
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=window s-1252">
<meta name="GENERATOR " content="Micros oft FrontPage 4.0">
<meta name="ProgId" content="FrontP age.Editor.Docu ment">
<title>New Page 2</title>
</head>
<body>
<SCRIPT LANGUAGE="JavaS cript1.2">

The language attribute was deprecated many years ago, type is reqired, use:

<script type="text/javascript">
Except that the draft for HTML 5 says the type attribute can be omitted
if the type is text/javascript, and the language attribute is no longer
deprecated (though its meaning has changed a little). :-(

>Indented code is easier to read for most of us.
<snip>

Hear, hear!

John
--
John Harris
Sep 12 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
11937
by: Nicholas Geraldi | last post by:
Im looking for a decent random number generator. Im looking to make a large number of random numbers (100 or so, if not more) in a short period of time (as fast as possible). the function i was using to get random numbers was Random rn = new Random(System.currentTimeMillis()); but it seems that the system doesn't update the milliseconds...
10
2490
by: Virus | last post by:
Ok well what I am trying to do is have 1.) the background color to change randomly with 5 different colors.(change on page load) 2,) 10 different quotes randomly fadeing in and out in random spots on the webpage. with a delay timer on them, so they keep changing as the page is open. Not random each time the page is loaded. If anyone...
10
2882
by: Sonoman | last post by:
Hi all: I am trying to write a simple program that simulates asking several persons their birth day and it counts how many persons are asked until two have the same birth day. The problem that I have is that the first loop I get a sequence of random numbers untuil I get a match, BUT then on the following loops I get the SAME random(?)...
10
741
by: Ioannis Vranos | last post by:
I want to create some random numbers for encryption purposes, and i wonder if the following scheme makes it more hard to guess the underneath number generation pattern, than the plain use of rand(): #include <stdlib.h> #include <time.h>
13
4216
by: quickcur | last post by:
Suppose I have a function rand() that can generate one integer random number between 0 and 100. Suppose also rand() is very expensive. What is the fastest way to generate 10 different random number between 0 and 100? (call rand() only 10 times...) Thanks, qq
4
4099
by: Dimos | last post by:
Hello All, I need some help with random number generation. What I need exactly is: To create a few thousand numbers, decimal and integers, between 5 and 90, and then to export them as a single column at a spreadsheet.
22
3414
by: gagan.singh.arora | last post by:
Hi there. I want to generate random numbers with a given probability, say 80% even and 20% odd. Is it possible to implement such an algorithm in C?
21
13490
by: chico_yallin | last post by:
I just wana make a random id number based on4 digits-for examples?? Thanks in Advance Ch.Yallin
8
7551
by: Anil Gupte | last post by:
I had someone write a random number generator in C# (I am more of a VB programmer) and they came up with the following: public string GetRand(int count) { string number = ""; for (int i=0; i<count; i++) { Random Rnd = new Random(); number = number+Convert.ToString(Rnd.Next(0,9));
16
539
by: jason.cipriani | last post by:
I am looking for a random number generator implementation with the following requirements: - Thread-safe, re-entrant. - Produces consistently reproducible sequences of psuedo-random numbers given a seed. - Relatively uniform, does not have to be perfect. The application is not a security or statistics application, the quality of numbers...
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.