you must develop a program that allows you to randomly pick an element from an array based on a weighting that is assigned to it. In programming terms, this is called a roulette wheel selection. To go along with this, and to ensure that you can desk-check this properly, you must also write a random number generator that takes in an integer value as a seed and then provides a deterministic number back. You must:

develop the pseudocode desk-check test the program to ensure that it works for appropriate sets of data The first part of your task is to develop the roulette wheel. Say you have the following array:

  • Yes
  • No
  • Maybe

And each of these elements is weighted:

Element Weighting
Yes 50
No 30
Maybe 20

A roulette wheel selection would ensure that, over a long enough run of a set of numbers, that yes would be picked 50% of the time, no would be picked 30% of the time, and maybe would be picked 20% of the time. You must write the function that allows for this to be done, either using two arrays (one with the element, one with the weightings) or a class.

Randomness is difficult to incorporate into a desk-check, and so you will provide your own random number generator. For this, you will use the middle square method1 of random number generation. This is not a good method of calculating random numbers, so you should not expect that the distributions seen in your roulette wheel are what you would expect from your weightings. This system uses a four digit starting number (known as a seed) which is then squared. The middle four numbers of the squared result is the output and becomes the seed of the next call of the generator. When generating random numbers within your roulette wheel, you will use this method along with a fixed starting seed.

You should set up some starting values including an array of elements, their weightings, and then output the results of five sequential calls to the roulette wheel using these elements and an appropriate random number seed.

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.