Gossamer Forum
Home : Products : DBMan : Customization :

Random Search Mod again!

Quote Reply
Random Search Mod again!
JPD, I understand the problems involved with the counter, in trying to write a true random search mod, but is there any way of getting your dummy field random search mod to work a little better.
If we could fix a couple of things with it, then It may be useable.
First, it won't work when other search terms are specified, and seems to only work with list all.
Second, the random patten it produces, seems to be the same every time you search. It seems like it needs to be reset for each search some how.
Can it be fixed, or shall I give up on this one. I realy need a random search mod.
Anyone got any ideas.
Thanks
bob
Quote Reply
Re: Random Search Mod again! In reply to
 
Quote:
First, it won't work when other search terms are specified, and seems to only work with list all.

Right.

Quote:
Second, the random patten it produces, seems to be the same every time you search.

I'll have to see the code you're using to be able to help you with this. (I know I gave you the code, but it's been quite a while and I don't know what I gave you. Smile )

What kind of random search mod do you want? Do you want a random record returned or do you want the records in random order?




------------------
JPD





Quote Reply
Re: Random Search Mod again! In reply to
This is your random search code I'm using,
Code:
LINE: while (<DB> ) {
(/^#/) and next LINE; # Skip comment Lines.
(/^\s*$/) and next LINE; # Skip blank lines.
$line = $_; chomp ($line); # Remove trailing new line.
@values = &split_decode($line);
if ($in{'random'}) {
srand ( );
$values[1]=int(rand(1000)) + 1;
$in{'sb'} = 13;
}

What I would like to do is return 10 or 15 random records from the database, and I was hoping to it by category, but that dosn't seem possible, so I'll settle for what I can get as long as it will return a different result pattern for each search.
thanks
bob



[This message has been edited by lanerj (edited August 02, 1999).]

[This message has been edited by lanerj (edited August 02, 1999).]
Quote Reply
Re: Random Search Mod again! In reply to
Try moving the line

srand ( );

out of the loop. You can pretty much put it anywhere within sub query, as long as it's before the line that begins with

LINE:

I think the problem is that the seed is set every time.

Anyway, give that a try and see what happens. Then we can try to work on your other stuff.


------------------
JPD





Quote Reply
Re: Random Search Mod again! In reply to
JPD, I took srand(); out of the loop and put it above LINE:, but still no go. It still returns the same results pattern as before, over and over again. Frown
I have &random=1 added to the list all link.
thanks
bob
Quote Reply
Re: Random Search Mod again! In reply to
Here's a bit from "Programming Perl" about the srand function:

Quote:
srand EXPR

This function sets the random number seed for the rand operator. If EXPR is omitted, it does srand(time)....

Do not call srand multiple times in your program unless you know exactly what you're doing and why you're doing it. the point of the function is to "seed" the rand function so that rand can produce a differenct sequence each time you run your program. Just do it once at the top of your program, or you won't get random numbers out of rand!

I'm wondering if there may be a conflict with the random number generator in the auth.pl file. When I used the code I gave you, it was with the understanding that only default users would be seeing the random display, so that srand function wasn't a factor. Try taking out the srand altogether and see what happens.


------------------
JPD


[This message has been edited by JPDeni (edited August 04, 1999).]
Quote Reply
Re: Random Search Mod again! In reply to
JPD, I took srand() out of sub query, but still no go. It still displayes the same result pattern every time.
I am using default users, as my main search is via static html. I've tried &uid=default&Random=1&view_records=Go%21&ID=*, as a stand alone link, which works, but still returning the same pattern.
I have also the link on list all within dbman, which also returns the same pattern.
Now I am using whats_new_days and whats_new_records mod in sub query, maybe this is the problem.
I'm also modding off line on Xitami.
thanks
bob
Quote Reply
Re: Random Search Mod again! In reply to
You're using &Random=1?

No wonder you're having problems. It needs to be random=1 because the code is

if ($in{'random'}) {

Case counts!

Put things back the way they were and either change your link to &random=1 or change the code to

if ($in{'Random'}) {

Then give it a try.

------------------
JPD





Quote Reply
Re: Random Search Mod again! In reply to
Sorry, that was a typo. If it's the wrong case you get a no search term error.
I realy appriciate the time your spending on helping me with this, and I realy need a mod like this for my site, as my clients will be paying $50+ for a listing (because of the Real Media content), I therefore feel that they need the best chance of having there listing seen by users who browse.
Although I don't like giving up on somthing, I feel this may be the holy grail of mods, and I realy need to move on, so I can pick your brain on somthing else.
Maybe one day after a couple of good homemade snickerdoodles somthing may pop into your head. I'll keep checking.
Once again thanks for your time.
bob