help with a random number

Here is the code i am using to create a 2 digit random number. However at the moment it produces a number from 01 - 99 but i want it to produce a numer from 01 - 49. I dont want all the code changed. I was thinking of adding a loop but think i need some help.

Rand0="";
i = 1;
while (Number(i)<>3) {
     rnd = random(10);
     x = 1;
       while (Number(x)<>Number((Number(length(Rand0))+1))) {
          if ((substring(Rand0, x, 1)) eq rnd) {
               rnd = "";
          }
          x = Number(x)+1;
     }
     if (rnd ne "") {
          Rand0 = Rand0 add rnd;
          i = Number(i)+1;
     }
}
lukegriffiths110Asked:
Who is Participating?
 
BillystyxCommented:
but if you do want to change your code...
function rand(){
md=random(50);
}
if(md==0){
rand();
}

that way if you get a zero it runs the random no generator again until you get above 0

Billystyx
0
 
blue-genieCommented:
hi there, seems to me a very long winded way of generating a random number,

but if i understand you correctly, and since you don't want to change your code

changing this line

      rnd = random(5);//from 10
should give you want you want.

blu
0
 
BillystyxCommented:
function rand(){
md=random(50);
}
if(md==0){
rand();
}
if(md.length<2){
md="0"+md;
}
newmd=Number(md);

Billystyx
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
BillystyxCommented:
sorry, 1 change ...
rand();
function rand(){
md=random(50);
}
if(md==0){
rand();
}
if(md.length<2){
md="0"+md;
}
newmd=Number(md);
0
 
mateuszkrzeszowiecCommented:
numBear = Math.floor(Math.random()*48 + 1);
if(numBear < 10)
numBear = "0" + numBear;
+1 is becouse you dont want to have 00
0
 
mateuszkrzeszowiecCommented:
Sorry, mistake :D
You can check results with code below:
for(i=0;i<1000;i++) {
     numBear = Math.floor(Math.random()*49 + 1);
     if(numBear < 10)
          numBear = "0" + numBear;
     trace(numBear);
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.