lukegriffiths110
asked on
6 random numbers 0-49
Basically i dont want rand0 being the same as rand1 or rand2 etc i want six different randoly generated numbers from 01-49 its nearly there the code just needs some more work. Any help much appreciated.
rand1st();
function rand1st(){
Rand0="";
i = 1;
while (Number(i)<>3) {
rnd = random(5);
x = 1;
while (Number(x)<>Number((Number (length(Ra nd0))+1))) {
if ((substring(Rand0, x, 1)) eq rnd) {
rnd = "";
}
x = Number(x)+1;
}
if (rnd ne "") {
Rand0 = Rand0 add rnd;
i = Number(i)+1;
}
}
}
Rand1="";
i = 1;
while (Number(i)<>3) {
rnd = random(5);
x = 1;
while (Number(x)<>Number((Number (length(Ra nd1))+1))) {
if ((substring(Rand1, x, 1)) eq rnd) {
rnd = "";
}
x = Number(x)+1;
}
if (rnd ne "") {
Rand1 = Rand1 add rnd;
i = Number(i)+1;
}
}
Rand2="";
i = 1;
while (Number(i)<>3) {
rnd = random(5);
x = 1;
while (Number(x)<>Number((Number (length(Ra nd2))+1))) {
if ((substring(Rand2, x, 1)) eq rnd) {
rnd = "";
}
x = Number(x)+1;
}
if (rnd ne "") {
Rand2 = Rand2 add rnd;
i = Number(i)+1;
}
}
Rand3="";
i = 1;
while (Number(i)<>3) {
rnd = random(5);
x = 1;
while (Number(x)<>Number((Number (length(Ra nd2))+1))) {
if ((substring(Rand2, x, 1)) eq rnd) {
rnd = "";
}
x = Number(x)+1;
}
if (rnd ne "") {
Rand2 = Rand2 add rnd;
i = Number(i)+1;
}
}
Rand4="";
i = 1;
while (Number(i)<>3) {
rnd = random(5);
x = 1;
while (Number(x)<>Number((Number (length(Ra nd2))+1))) {
if ((substring(Rand2, x, 1)) eq rnd) {
rnd = "";
}
x = Number(x)+1;
}
if (rnd ne "") {
Rand2 = Rand2 add rnd;
i = Number(i)+1;
}
}
Rand5="";
i = 1;
while (Number(i)<>3) {
rnd = random(5);
x = 1;
while (Number(x)<>Number((Number (length(Ra nd2))+1))) {
if ((substring(Rand2, x, 1)) eq rnd) {
rnd = "";
}
x = Number(x)+1;
}
if (rnd ne "") {
Rand2 = Rand2 add rnd;
i = Number(i)+1;
}
}
if(rand1==rand0){
rand1st();
}
rand1st();
function rand1st(){
Rand0="";
i = 1;
while (Number(i)<>3) {
rnd = random(5);
x = 1;
while (Number(x)<>Number((Number
if ((substring(Rand0, x, 1)) eq rnd) {
rnd = "";
}
x = Number(x)+1;
}
if (rnd ne "") {
Rand0 = Rand0 add rnd;
i = Number(i)+1;
}
}
}
Rand1="";
i = 1;
while (Number(i)<>3) {
rnd = random(5);
x = 1;
while (Number(x)<>Number((Number
if ((substring(Rand1, x, 1)) eq rnd) {
rnd = "";
}
x = Number(x)+1;
}
if (rnd ne "") {
Rand1 = Rand1 add rnd;
i = Number(i)+1;
}
}
Rand2="";
i = 1;
while (Number(i)<>3) {
rnd = random(5);
x = 1;
while (Number(x)<>Number((Number
if ((substring(Rand2, x, 1)) eq rnd) {
rnd = "";
}
x = Number(x)+1;
}
if (rnd ne "") {
Rand2 = Rand2 add rnd;
i = Number(i)+1;
}
}
Rand3="";
i = 1;
while (Number(i)<>3) {
rnd = random(5);
x = 1;
while (Number(x)<>Number((Number
if ((substring(Rand2, x, 1)) eq rnd) {
rnd = "";
}
x = Number(x)+1;
}
if (rnd ne "") {
Rand2 = Rand2 add rnd;
i = Number(i)+1;
}
}
Rand4="";
i = 1;
while (Number(i)<>3) {
rnd = random(5);
x = 1;
while (Number(x)<>Number((Number
if ((substring(Rand2, x, 1)) eq rnd) {
rnd = "";
}
x = Number(x)+1;
}
if (rnd ne "") {
Rand2 = Rand2 add rnd;
i = Number(i)+1;
}
}
Rand5="";
i = 1;
while (Number(i)<>3) {
rnd = random(5);
x = 1;
while (Number(x)<>Number((Number
if ((substring(Rand2, x, 1)) eq rnd) {
rnd = "";
}
x = Number(x)+1;
}
if (rnd ne "") {
Rand2 = Rand2 add rnd;
i = Number(i)+1;
}
}
if(rand1==rand0){
rand1st();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
inside bit should look like this:
myArr=[];
function shuffle() {
if (random(50)) {
return 1;
}
}
for(var i = 1; i < 50; i++){//this section changed...
if(i<10){
myArr.push("0"+i);
}else{
myArr.push(i);
}
}
myArr.sort(shuffle);
for(i=0;i<6;i++){
_root["Rand"+i]=myArr[i];
}
Billystyx
(not much different now...)
myArr=[];
function shuffle() {
if (random(50)) {
return 1;
}
}
for(var i = 1; i < 50; i++){//this section changed...
if(i<10){
myArr.push("0"+i);
}else{
myArr.push(i);
}
}
myArr.sort(shuffle);
for(i=0;i<6;i++){
_root["Rand"+i]=myArr[i];
}
Billystyx
(not much different now...)
hmmnn seems like repeated question... anyway... try this...
function randomnumbers(lowest, highest, count) {
var randomnums = new Array();
if (count<=highest-lowest) {
var nums = new Array();
for (var i = lowest; i<=highest; ++i) {
nums.push(i);
}
for (var i = 1; i<=count; ++i) {
var randomnumber = Math.floor(Math.random()*n ums.length );
randomnums.push(nums[rando mnumber]);
nums.splice(randomnumber, 1);
}
}
return randomnums;
};
myrandom = randomnumbers(1, 49, 6);
trace(myrandom);
function randomnumbers(lowest, highest, count) {
var randomnums = new Array();
if (count<=highest-lowest) {
var nums = new Array();
for (var i = lowest; i<=highest; ++i) {
nums.push(i);
}
for (var i = 1; i<=count; ++i) {
var randomnumber = Math.floor(Math.random()*n
randomnums.push(nums[rando
nums.splice(randomnumber, 1);
}
}
return randomnums;
};
myrandom = randomnumbers(1, 49, 6);
trace(myrandom);
myArr=[];
function shuffle() {
if (random(50)) {
return 1;
}
}
for(var i = 1; i < 50; i++){
myArr.push(i);
}
myArr.sort(shuffle);
for(i=0;i<6;i++){
_root["Rand"+i]=myArr[i];
}
(same as negatyves I think but shorter:)
Billystyx