In comp.lang.javascript message <47************@PointedEars.de>, Sun, 28
Oct 2007 19:23:30, Thomas 'PointedEars' Lahn <Po*********@web.de>
posted:
>McKirahan wrote:
>Can someone show me the JavaScript equivalent
to the following VBScript? Thanks in advance.
Randomize
For i = 0 to 15
intRnd = Int((16 * Rnd) + 1)
Next
Perhaps the follwoing is a start?
var Rnd = Math.floor(Math.random() * 16);
for (i=0; i<16; i++) {
// ?
}
It isn't reasonable to assume that subscribers know a language that is
off-topic in the newsgroup(s) being posted to;
Perhaps that's why he's asking whether anyone can do it. Anyone capable
of answering the question in the form you suggest will be able, from the
information provided, to answer.
you should have posted a
description of what you are trying to do instead.
Anyhow, you are looking for this:
function rnd()
{
var n = Math.random();
// Opera ECMAScript bugfix
if (n == 1)
n = 0;
return n;
}
function rnd() { return Math.random()%1 }
is simpler; and in IE6 it appears only about 10% slower.
According to a link in the FAQ, the Opera bug applied in Opera 5.02 to
6.01, but not in 6.05, which was available by 2003-08-04. It was said
to occur once per about 35000 times (?? 32768 ??), so the fact that a
test now running on this machine has not found it in over 3.2e9 attempts
using Opera 9.24
(a) supports what I wrote recently about FAQ & wait-loops,
(b) suggests that any reference to Opera having that bug really
should refer to "Old Opera" or equivalent.
It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.