Using JavaScript foundation random number and stochastic picture

In: Uncategorized

19 Jul 2007

Foundation random number
(1) produces since JavaScript in, in many browsers all
has the random number which sets to have the method. For
example:

Var number = Math.random
();

This method produces 0 to 1 between floating number.

(2) based on the time, also may have the random number.
For example:

Var now=new Date ();

Var number = now.getSeconds ();

This produces based on the present time 0 to 59 integers.

Var now=new Date ();

Var number = now.getSeconds () %43;

This produces based on the present time 0 to 42 integers.

(3) here introduced a quite outstanding random number generator
procedure, can apply to many domains.

// The Central Randomizer 1.3 (C) 1,997 by Paul Houle (houle@msc.cornell.edu)

// See: Http://www.msc.cornell.edu/~houle/javascript/randomizer.html

Rnd.today=new Date ();

Rnd.seed=rnd.today.getTime ();

Function rnd () {

Rnd.seed = (rnd.seed*9301+49297) % 233,280;

Return rnd.seed/ (233280.0);

};

Function rand (number) {

Return Math.ceil (rnd () *number);

};

// end central randomizer. –>

If must use this random number generator in yours
homepage, must put this section of code on and between the mark.

When must found a stochastic floating number, uses rnd ();
When must found a stochastic integer, for example, 1 to 10
o’clock, uses rand (10).

Under founds the stochastic picture in the example, is has the
random number with this random number generator under, therefore, must
enable the example the normal work above, must guarantee in your
homepage to contain this section of code.

Founds the stochastic picture
Founds the stochastic picture, this was uses the
simplest matter which the random number could do. In this
example, our supposition has 10 pictures, banner1.gif….
banner10.gif, when the documents writes down, we hoped can
stochastically demonstrate these pictures.

Document.write (”);

//–>

If the picture is not, or the picture type or the size
which names by the digital form when are dissimilar, then, you also
may through the inspection random number value, then the demonstration
corresponding picture:

Var number = rand (10);

If (number == 1) {

Var picture = “one.gif”; Var width = 400; Var height = 40;

}

Else if (number == 2) {

Var picture = “two.jpg”; Var width = 200; Var height = 20;

}

Else if (number == 9) {

Var picture = “nine.gif”; Var width = 450; Var height = 450;

}

Else if (number == 10) {

Var picture = “ten.jpg”; Var width = 40; Var height = 400;

}

Document.write (”);

//–>

How stochastic demonstration picture above introduced,
similar truth, also may found stochastic text, table list, title
advertisement, URL, background color and picture,
examination table and frame and so on, using the random number here no
longer said.

Comment Form

You must be logged in to post a comment.

About this blog

Just for web admin!

Photostream