|
-
Jul 17th, 2002, 11:55 AM
#3
Thread Starter
Addicted Member
In understand what your saying, but there is still a problem. You see, each item must have its own high and low range that no other item shares. For example,
item(0).low = 0 and item(0).high = 10
item(1).low = 10 and item(1).high = 20
x = rnd * 20
if x >= item(i).low and x < item(i).high then choose the item #.
i did this with ten items, 0-9, and gave them each a range of 10 (x = rnd * 100). After looping 100,000 times and keeping track of how many times each was choosen, they each were chosen about 10% of the time (go figure...). The problem with having the items have overlapping ranges is that it's possible for a number x to be equal to several different items, and the choice of items being made solely upon the value of i.
For instance say item 1 and item 7 share the range 10(low) and 20(high). If x is 15 then it could be 1 or 7, and whenever x = 10-20 it will always choose item # 1 because that comes first in the loop (i = 0 to 9).
The problem with having ranges that don't overlap is that when you want to change the range of one, you have to change the range of the rest. It is this problem of which I am wondering if there is another way around.
thanks again,
jmiller
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|