By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,681 Members | 1,864 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,681 IT Pros & Developers. It's quick & easy.

I need a pick-3 style javascript

P: n/a
I've searched high and low for a 3 digit number generator that will
pick at random a number between 000 and 999.

The only things I have found were generators that pick numbers from 0
to 999.

I want one that if the number picked is 0 through 99 it is generated
as 000 through 099.

Can anyone help me with this? Cause I'm stumpt.
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Lee
Jules said:

I've searched high and low for a 3 digit number generator that will
pick at random a number between 000 and 999.

The only things I have found were generators that pick numbers from 0
to 999.

I want one that if the number picked is 0 through 99 it is generated
as 000 through 099.

Can anyone help me with this? Cause I'm stumpt.

function pick3(){
return ("00"+Math.floor(Math.random()*1000)).substr(-3);
}

Jul 20 '05 #2

P: n/a
qqchose comme : prendre les 3 derniers caractères de
((Math.random + 1) * 1000 )

Jules a écrit:
I've searched high and low for a 3 digit number generator that will
pick at random a number between 000 and 999.

The only things I have found were generators that pick numbers from 0
to 999.

I want one that if the number picked is 0 through 99 it is generated
as 000 through 099.

Can anyone help me with this? Cause I'm stumpt.


Jul 20 '05 #3

P: n/a
JRS: In article <d7**************************@posting.google.com >, seen
in news:comp.lang.javascript, Jules <jh****@yahoo.com> posted at Fri, 30
Jan 2004 13:42:18 :-
I've searched high and low for a 3 digit number generator that will
pick at random a number between 000 and 999.

The only things I have found were generators that pick numbers from 0
to 999.

I want one that if the number picked is 0 through 99 it is generated
as 000 through 099.


A Number is a Number, a numeric value stored as an IEEE Double. What
you are actually calling for is a String of three decimal digits.

Obvious ways are

function Random(N) { return Math.floor(N*(Math.random()%1)) } // in FAQ
// but %1 : Opera

/* 1 */ S = "" ; for (j=0 ; j<3 ; j++) S += Random(10)
/* 2 */ S = String(1000+Random(1000)).substring(1)

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.