I‘m not sure if i got you right, but i think you would need to make rate0 into an array and call the respective int in the array inside the Function :
void rateChoose(int i) {
int tempRate = 0;
for (int i = 0; i < 7; i++) {//i don‘t know why you need this, but i‘ll just leave it
tempRate = tempRate * 10 +int(random(10));
}
rate[i] = tempRate;
}
rateChoose(0);
rateChoose(1);
rateChoose(2);
or
void rateChoose() {
int tempRate;
for (int i = 1; i< 7; i++) { //again, don‘t know why the for loop...
tempRate =tempRate* 10+ int(random(10));
}
return tempRate;
}
rate[0] = rateChoose();
rate[1] = rateChoose();
This would do what you want… If i got you right. There is a way to make it easier, but i don‘t know the context, so i can‘t Tell what could be changed and what wouldn‘t Work. I could help more if i knew what you want to do exactly…
Anyway, Hope this helps ^^
this is my function; I want to replace the random 100000 with a 6 digit call to random 0-9 . I thought it would be easy but cant get my head around the function call.
Oh ok, i think i got it now, but why? random(100000) is exactly the same as Setting each digit to be random… anyway, in this case you can just do this :
int rateChoose() {
int result;
for (int i = 0; i < 6; i++) {
result = result*10+int(random(10));
}
return result;
}
{
int rate1 = rateChoose();
int rate2 = rateChoose();
}
You can also make it customizable by adding parameters like… instead of having a 6digit number you could do :
int rateChoose(int digitLength) {
for (int i = 0; i < digitLength; i++) {
....
}
....
}
Or
int rateChoose(int maxDigit) {
for (int i = 0; i < 6; i++) {
result = result * 10 + int(random(maxDigit));
}
}
So that if maxDigit is 8, the highest number possible is 888888 and you can‘t get any number with a 9 in it.
I still don‘t know why you would need that, but Hope this helps ^^
thank you. That is great. Simple and sweet. I would not have been able to work it out from the examples and info on the processing page. just for your info. It was like to simulate dialing on a phone. choose a random number ,then dial that, then next then dial that rather than choose all the numbers first then dial them. I am sure I did that as a kid . wondering who i would dial up.