Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 23rd, 2005, 03:00 PM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Default javascript: help needed

hello
i've just registered with this forum and this iz my 1st post
actually i m stucked in a problem in JavaScript ... n i hope that someone will help me

i want 2 develop a program in javascript ... that generates 100 random numbers from 0 to 99 ... n all those random numbers are to be stored in a 100 length array ... but the actual thing iz that all the rendomly generated numbers should be unique and there should be no duplication ...
at last there should be a complete array of 100 elements having 0 to 99 numbers randomly stored in it ... i mean any number on any index

i hope i'll get my answer as soon as possible ... bcoz there r so many experts in this form and i'll learn so much here

waiting 4 a good reply
Reply With Quote
  #2 (permalink)  
Old August 24th, 2005, 06:55 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Kanoorani!!
Offcourse you can do this,
hope this will help you
******test.html****
<form name="myform">
<textarea name="mt" ></textarea>
<input type=button onclick="setVal()">
</form>
<script>
var
flag=true;
var myaray
myarray=new Array()
var myarrayString
loopcounter=0
function setVal()
{
str=""
newstr="/"
var currval;
var flag
flag=true;

 while(flag)
     {
      currval=rnd(1,100)
      str="/"+ currval+"/"

      if(newstr.indexOf(str)==-1)
       {
     //alert(loopcounter)
       myarray[loopcounter]=currval;
       loopcounter++;
       if(loopcounter==100)
        {
        flag=false
         }
         newstr=newstr+currval+"/"
       }

       myarrayString=myarray.join("~");

     }
document.myform.mt.value=myarrayString

myarray.sort(compareNum)
for(i=0;i<myarray.length;i++)
{
alert(myarray[i]);
}

}
function setRnd()
{
setVal()
}


function rnd(a,b) {
    return a + Math.floor(Math.random()*(b-a+1));
}

function compareNum(a,b)
{
return a-b
}
</script>

****8test.html******end*******

please comment following lines,this is just to show sort function

myarray.sort(compareNum)
for(i=0;i<myarray.length;i++)
{
alert(myarray[i]);
}



Cheers :)

vinod
Reply With Quote
  #3 (permalink)  
Old August 24th, 2005, 07:25 AM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello
thankx alot my friend ... it worked really very nice ... i'll b contacting u in future if i face n.e problem ... thankx once more

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
stop current javascript function using javascript sakthi Javascript 3 June 2nd, 2008 03:30 PM
HELP NEEDED Yasho VB.NET 2002/2003 Basics 1 January 29th, 2007 08:13 AM
HELP NEEDED G.Mohanraj Other Programming Languages 1 January 23rd, 2006 01:22 PM
Help needed please please PhillipMorris Access ASP 4 September 23rd, 2003 11:39 PM



All times are GMT -4. The time now is 01:09 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.