473,508 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

generate random w/ weighting

I need to randomly pick films from a list to automatically generate a
timetable. Each film has a priority and weighting that affects how often it
is picked. For example, say we have 3 films with the following priority and
weighting,

A 1 5%
B 2 10%
C 3 5%

B should be picked more often because of the higher weighting. If films
have equal weighting, we look at the priority. So in this example, A should
have a higher 'overall weighting' than B.

Considering these factors, what is the best way to do this? Thanks.

jobz
Jul 21 '05 #1
1 1464
jobz <jo**@xmail.com> wrote:
I need to randomly pick films from a list to automatically generate a
timetable. Each film has a priority and weighting that affects how often it
is picked. For example, say we have 3 films with the following priority and
weighting,

A 1 5%
B 2 10%
C 3 5%

B should be picked more often because of the higher weighting. If films
have equal weighting, we look at the priority. So in this example, A should
have a higher 'overall weighting' than B.

Considering these factors, what is the best way to do this? Thanks.


Well, the "percent" in the above is somewhat confusing given that they
don't add up to 100, however:

Create a list, and for each element, add the outcome and the boundary
value it's valid for, ie the previous boundary (beginning with 0) +
weight.

You'll end up with a boundary being the total of all the weights.
Generate a random number between 0 and total-1
(ie Random.NextInt(total)) then step through the list until you find
the first element which has a boundary higher than that randomly
generated number.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4811
by: Alexander Ross | last post by:
is there any way to get a weighted random number other than something like this: array = (1,2,2,3,3,3,4,4,4,5,5,6) and then get a random val from teh array? Alex
2
8273
by: Laphan | last post by:
Hi All This is a strange request, but I just cannot fathom how to do it. In theory the requirement is very basic, but in practise its a noodle!! I have 10 team names like so: Team A Team...
1
1696
by: jhicsupt via AccessMonster.com | last post by:
Bear with me – a long question but hopefully someone can help me. I have a survey which uses weighting to get the final score. I’m trying to find the best way to calculate the final score. I...
15
4926
by: John Cassidy | last post by:
This has been driving me crazy. I've done basic C in school, but my education is mainly based on object oriented design theory where Java is our tool. For some reason, while helping a friend with a...
2
18002
by: Henry | last post by:
Hi, How can I generate an eight digit random? Can I use the staff name to generate it? May I ask is there any sample c# code to see? Thanks
1
201
by: jobz | last post by:
I need to randomly pick films from a list to automatically generate a timetable. Each film has a priority and weighting that affects how often it is picked. For example, say we have 3 films with...
6
3062
by: comp.lang.php | last post by:
/** * Generate the random security image * * @access public * @param $willUseFilePath (default false) boolean to determine if you will be using a file path * @param mixed $filePath (optional)...
9
9936
by: MyInfoStation | last post by:
Hi all, I am a newbie to Python and would like to genereate some numbers according to geometric distribution. However, the Python Random package seems do not have implemented functionality. I am...
20
7810
by: jjmillertime | last post by:
I'm new so i apologize if this is in the wrong spot. I'm also new to programming in C and i've been searching for quite a while on how to create a program using C that will generate two random...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7499
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1561
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.