That helps more than I can say.
Wait a minute. You said you wanted some kind of weighting, right? I just thought of something. You could add together a certain number of random numbers, which would end up giving you a "bell curve" of possibilities.
For example, if you added 3 random numbers, each ranging from 1 to 4, you would get the following probability distribution:
3 -- 1
4 -- 3
5 -- 6
6 -- 10
7 -- 12
8 -- 12
9 -- 10
10 -- 6
11 -- 3
12 -- 1
If you wanted to keep your numbers from 1 to 10, you would just need to subtract 2 from the total. So computing the random number for the user would be:
Code:
for ($r=1;$r<4 ;++$r) {
$in{'random'} += int(rand(4)) + 1;
}
$random -= 2;
I'm not quite sure what you would do with it, though. If you assigned the records based on the distribution, users would have different probabilities of getting a certain list, but not different probabilities of getting a certain record. Is that what you want?
Of course, you could use any numbers you wanted -- random numbers ranging from 1 to whatever and any number of random numbers added together. It would all result in a bell curve sort of weighting. (I got all this from remembering when I used to play tabletop role-playing games.
)
The thought I had was to generate the random number at the time the user signs in and saving it to the session file for the user. This has several advantages. One is that you don't have to add hidden fields to your forms and text to your links in order to pass the random number each time the script is invoked. The other is that the user could not change his random number in the URL.
To do this, in auth.pl, sub auth_check_password, change
print AUTH "$uid: $ENV{'REMOTE_HOST'}\n"; to
Code:
$in{'random'} = whatever your random number generation routine is;
print AUTH "$in{'random'}\n";
Then in sub auth_check_permissions, before
open (PER, "<$auth_pw_file") or &cgierr(" add
Code:
open(AUTH, "<$auth_dir/$db_uid") or &cgierr("unable to open auth file: $auth_dir/$uid. Reason: $!\n");
@random=<AUTH>;
close AUTH;
$in{'random} = $random[0];
chomp $in{'random'};
In fact, the best thing to do would be to either name your field with your random numbers
random or to change every instance of
$in{'random'} above to match your fieldname. That way when you did a search, the search term would always be there. I don't think you would have to add any more code.
A couple of other things I've thought of while writing this: You should probably only have as many records with a given number as will fit on a page. IOW, if your $db_max_hits is set to 10, then you should only have 10 records with the number 6 in the random field.
The other thing is that you should probably set $in{'ww'}=1 always in sub query. Otherwise, if the user's number is 1, he will get both records with 1 and with 10 in the field.
Let me know if this is all clear as mud.
JPD