generation vs verification
i was wondering if i am generating a number give an input and i want to then verify that the pairs are valid..would I store the result somewhere? I am not inclined to since I could run a million inputs through. Perhaps in my verification function I just call the generation function which generates the random code 开发者_开发技巧for a given input and then compare key pairs? that way I don't ahve to keep a file or storage area where to do look ups etc? I am not sure which would be a better solution or an eligant way of doing this.
The reasonable way is to have generate function separate from verify function and then just process thing on-the-fly.
int generate_random() { /* ... */ }
bool verify_result(int arg) { /* ... */ }
int main()
{
for (int = i; i < 1000000; ++i)
{
int n = generate_random();
if (!verify_result(n)) { /* launch missile */ }
}
}
(You didn't provide much details of your task, but for most cases storing million of numbers in file just to verify 'em later is not wise).
精彩评论