473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

JS equivalent of VBScript "Rnd"?

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++) {
// ?
}
Oct 28 '07 #1
2 3486
In comp.lang.javascript message <0LednXPMQo3tXbnanZ2dnUVZ_qqgnZ2d@comcas
t.com>, Sun, 28 Oct 2007 11:58:24, McKirahan <Ne**@McKirahan.com>
posted:
>Can someone show me the JavaScript equivalent
to the following VBScript? Thanks in advance.
This newsgroup has a FAQ. Use it.
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 is, no more & no less.

Read <URL:http://www.merlyn.demon.co.uk/js-randm.htm too.

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.
Oct 28 '07 #2
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.
Oct 29 '07 #3

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

Similar topics

0
by: Andreas Suurkuusk | last post by:
Hi, I just noticed your post in the "C# memory problem: no end for our problem?" thread. In the post you implied that I do not how the garbage collector works and that I mislead people. Since...
4
by: jrasmussen | last post by:
I have created an Excel spreadsheet for the web. When it opens in IE 6.0 I get the message that the format is not supported. This is because it is in tab delimited format. Ane when I save the file,...
1
by: Leslie | last post by:
I need to get 20 random records from a table based on a condition. The condition isn't a problem. I have tried select top 20 *, rnd(field) from table, but that gets me the top 20 records. I need...
9
by: Frederik | last post by:
Hi all, I'm building a C# application that uses a M$ Acces database. In one of the queries I use something like the following: SELECT id FROM mytable WHERE id IN (20, 12, 21, 14) The result...
4
by: yf | last post by:
A KB article "http://support.microsoft.com/default.aspx?scid=kb;en-us;209599" tells that the maximum number of records that a table may hold if the PRIMARY key data type is set to AUTONUMBER is...
5
by: Steven | last post by:
Can anyone tell me how to toggle the "Caps Lock" key? Thanks in advance
2
by: Terry Lee Tucker | last post by:
Let me explain: I have written a "C" function which contains calls to other functions, all of which work with an API to a mileage database product called PCMiler. These functions make...
60
by: Dave | last post by:
I'm never quite sure whether to use "this." or not when referring to fields or properties in the same class. It obviously works just fine without it but sometimes I wonder if using this....
12
by: Pascal | last post by:
hello and soory for my english here is the query :"how to split a string in a random way" I try my first shot in vb 2005 express and would like to split a number in several pieces in a random way...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.