Stored Proc not Working Properly

# Thread: Stored Proc not Working Properly

1. Senior Member
Join Date
Dec 1969
Posts
431

## Stored Proc not Working Properly

2. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Stored Proc not Working Properly

Well, that&#039;s the problem with randomness. It&#039;s random.<BR><BR>Okay, in computing terms it&#039;s not random, but lets concentrate on the theory of what random is. In this case, you&#039;re talking about creating an equal chance of all of the banners being hit.<BR><BR>Even with an equal chance of that happening, it&#039;s theoretically possible (improbable, but possible) of a banner being chosen 50 times on the trot. Because it&#039;s random.<BR><BR>Maybe, if you&#039;re after these counts being closer, you&#039;re better off looking towards how to weight each of the values so that your code automatically makes up for poor banner 39 that seems to be chosen so few times.<BR><BR>Craig.

3. Senior Member
Join Date
Dec 1969
Posts
431

## RE: Stored Proc not Working Properly

I understand that, and that has definitely crossed my mind, but 132 to 4851....that is an outrageous gap, don&#039;t ya think?<BR><BR>Guess I may have to look into the weighing solution....

4. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Stored Proc not Working Properly

But look at the other ones. They&#039;re not that far apart.<BR><BR>And, even assuming these have an equal chance of being picked, there&#039;s 80% chance of other than 39, and 20% chance of 39.<BR><BR>Remember, this is all assuming that these are completely random picks. Computers typically don&#039;t make random picks - they make picks based on obscure calculations and seed values. They&#039;re not 100% (heh) random.<BR><BR>As I said - if you REALLY want these numbers to be similar then you&#039;re going to have to implement some kind of weighting to "balance out the randomness". It&#039;s unfortunate that that particular banner is being picked so few times, but it&#039;s not mathematically impossible - not by a long shot.<BR><BR>Craig.

5. Senior Member
Join Date
Dec 1969
Posts
431

## RE: Stored Proc not Working Properly

The strangest part is that this banner is consistently being picked the least amount, day after day.<BR><BR>Thanks again....

6. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Stored Proc not Working Properly

This is from books online:<BR><BR><BR>A common way to generate random numbers from RAND is to include something relatively variable as the seed value, such as adding several parts of a GETDATE:<BR><BR>SELECT RAND( (DATEPART(mm, GETDATE()) * 100000 )<BR> + (DATEPART(ss, GETDATE()) * 1000 )<BR> + DATEPART(ms, GETDATE()) )<BR><BR><BR>Maybe something like that would help to "randomise" your values more...?<BR><BR>Craig.

7. Senior Member
Join Date
Dec 1969
Posts
16,931

## Hmm... Ignore that.

Because of the way yours works, it&#039;ll end up passing a very int to RAND() each time (because it&#039;s executed several times in a single SP).<BR><BR>Hmm.<BR><BR>Craig.

8. Senior Member
Join Date
Dec 1969
Posts
431

## RE: Hmm... Ignore that.

FYI, I did find a little bug in my COUNT code which changed the counts I posted earlier, so that brought some relief. Although the counts are still not as close as I would like, they are a lot closer. I am going to just leave it as is for now and check the counts again in a week to see if they have become any closer, or possibly favor a different banner this time, which would be fine.<BR><BR>Thanks!

9. Senior Member
Join Date
Dec 1969
Posts
16,931

## Good good.

As you can tell from me going to Books Online - even though I believed my randomness story, I wanted to see if there was something else.<BR><BR>I agree - it was one hell of a gap.<BR><BR>:-)<BR><BR>Craig.

10. Senior Member
Join Date
Dec 1969
Posts
431

## RE: Good good.

Thanks for all the help!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•