473,549 Members | 3,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3493
In comp.lang.javas cript message <0LednXPMQo3tXb nanZ2dnUVZ_qqgn Z2d@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.demo n.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.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.
Oct 28 '07 #2
In comp.lang.javas cript message <47************ @PointedEars.de >, Sun, 28
Oct 2007 19:23:30, Thomas 'PointedEars' Lahn <Po*********@we b.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.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.
Oct 29 '07 #3

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

Similar topics

0
2035
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 the thread is over a month old, I decided to start a new one with my response. Please see my comments inline.
4
54781
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, It saves it as txt. How can this file be created so that Excel sees it as an .xls format. I created the data in VB 6.0 with a vbtab to seperate the...
1
1427
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 20 random records. I would prefer to use SQL only for this if it is possible. Thanks in advance.
9
9582
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 is fine, except that the order of the id's is not preserved. It seems to be ordered ascending. How can I keep the order I used as input?
4
5152
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 4,294,967,295. Suppose the PRIMARY key data type is set to "RANDOM" AutoNumber. Suppose an application (a) successfully INSERTS "X" records, then...
5
3431
by: Steven | last post by:
Can anyone tell me how to toggle the "Caps Lock" key? Thanks in advance
2
2667
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 connections to the PCMiler databae, do error checking on the origin and destination, get directions, etc. There is only one function loaded into postgres and...
60
5002
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. consistently may make the code easier to understand for someone else, etc. Using "this." makes it immediately clear, for example, that the variable being...
12
3202
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 without success. for example if the number is 123 456 : i would like to have some random strings like theese : (12 * 10 000) + (345 * 10) + (6*1)...
0
7446
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...
0
7718
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7470
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
7809
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
6041
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
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
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
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.