input: 8 numbers
output:a random number between 1-100 base on the input numbers
any idea for doing this ?
input: 8 numbers
output:a random number between 1-100 base on the input numbers
any idea for doing this ?
Post some code first. As far as the random number goes, read this SRAND - set seed for random number generation.
i know how s rand and rand work but if i use them its not base on the numbers!
i want the program choose random numbers in some rule
for example if more than half of numbers are lower than 1000 the chance for give output numbers that are lower than 50 increese by 20 percent or sth like this!
Why?
Anyway, here's an approach. (Why anyone would use it rather than a direct rand() value is beyond me though)
Code:int randbased(input *array) // input is in array[0] to array[7] { int k, s = 0; for (k = 0; k < 8; k++) s += input[k]; for (k = 0; k < s; k++) rand(); /* ignore s random numbers */ return rand(); }
We are neither telepathic nor omniscient, you know.
You need to define those rules for us to be able to help you.
If you don't know the rules, but can show a complete set of inputs and outputs, then we can help you deduce the rules. Then we can help you implement those rules in code. But we cannot divine your wishes.
Please be specific, as vague partial examples are just frustrating to everyone. We need detailed, specific information, to help you.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
as i said before i want the program do this...
Code:#include <stdio.h> int main() { int a[8]; int i,b; for(i=0;i<8;i++) scanf("%d",&a[i]); for(i=0;i<8;i++) if(a[i]<100) b++; if(b>4) //give a random number lower than 200 that its chance for become lower than 100 is 2times more than becom higher than 100 {} }
Last edited by king_zart; 11-06-2012 at 03:51 AM.
Generate a random number between 0 and 300.
If it is greater or equal to 200, subtract 200, getting a new number between 0 and 100.
Result: numbers between 0 and 100 are twice more likely to come up than numbers between 100 and 200.
Yeah I can't help you, you keep adding random weird requirements every time you post.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"