# Generating Random Numbers

1. ## Generating Random Numbers

I'm currently creating a darts scoreboard, and was looking to implement a 1 player v computer game where the computers scores generate random numbers between 0-180. Ideally I'd have 3 or 4 levels where on the hardest level the numbers generated were higher than the ones on the lowest level.

I'm sure there'd be a way to do this, but wouldn't really know where to start.

The further additional problem I have is when it gets close to finishing the game. On the hardest levels, the computer would finish the game (i.e. get to zero) a lot quicker than on the lower levels (where the computer might get down to a low number but take 2 or 3 attempts to get to zero)

Does anyone have any ideas on how to implement this, or if it is even possible in excel?

2. ## Re: Generating Random Numbers

Hi,

You could put 1 to 180 in column A of a data sheet, then run this to select a random cell:

``Please Login or Register  to view this content.``
to increase the odds of hitting a lower number rather than a high number, increase the number of observations at the low end. ie, have five 1s five 2s etc. , but only one 180 value. then adjust your defined range to suit. different levels could be accomplished by having different columns increasing the number of values at the high end (for the computer).

3. ## Re: Generating Random Numbers

Originally Posted by djdjdj
Hi,

You could put 1 to 180 in column A of a data sheet, then run this to select a random cell:

``Please Login or Register  to view this content.``
to increase the odds of hitting a lower number rather than a high number, increase the number of observations at the low end. ie, have five 1s five 2s etc. , but only one 180 value. then adjust your defined range to suit. different levels could be accomplished by having different columns increasing the number of values at the high end (for the computer).
Thanks for that. That makes sense that I add more chances of higher numbers for the harder levels.

Any idea about the finishing part?

4. ## Re: Generating Random Numbers

Hi

Re the first Q. Do you mean that ON AVERAGE with a hard level you'd get more numbers in say the range 91-180 than you would with an easy level?

If so then perhaps one way would be to generate a random number between 1 and x where x = 180 less the hardness level x 10. and then add the level hardness x 10 y times out of say 3.

e.g. with a level 4, generate a number between 1 & 140, then apply another random number IF test to generate a number between 1 & 5, and if the random number is >4 then add 4 * 10. This will skew the numbers towards the top. For other levels use a different > value in the IF.

I'd need to understand with some example numbers what you mean by the game finish limitation.

5. ## Re: Generating Random Numbers

Originally Posted by Richard Buttrey
Hi

Re the first Q. Do you mean that ON AVERAGE with a hard level you'd get more numbers in say the range 91-180 than you would with an easy level?

If so then perhaps one way would be to generate a random number between 1 and x where x = 180 less the hardness level x 10. and then add the level hardness x 10 y times out of say 3.

e.g. with a level 4, generate a number between 1 & 140, then apply another random number IF test to generate a number between 1 & 5, and if the random number is >4 then add 4 * 10. This will skew the numbers towards the top. For other levels use a different > value in the IF.

I'd need to understand with some example numbers what you mean by the game finish limitation.
Again that makes sense. Any idea how I'd implement that using VBA though?

For the finishing part, I'm not sure if you're aware of the game of darts, but you need to finish a game on a double (i.e. if your score is 20, you would need to hit the double 10 on the board rather than a single 20)

This obviously makes finishing a bit more difficult, however as the level difficulty increases the finishing improves. i.e. at easy level the score might get to 20 and the player would take 5/6/7 attempts to finish from there, whereas at hard level a player would take 1/2 attempts.

Similarly, if an easy level player had a score of 100+ left, then they would rarely finish from this position. However, at hard level, a player would finish from this sort of score maybe once every 5 or 6 times.

Does that make sense?

I think it can be easy to understand in English, but not so easy to implement in excel.

Hopefully this makes sense and you're able to help, but happy to provide more information, or sample spreadsheets if needed

6. ## Re: Generating Random Numbers

I think you should arrange your cell values, ie the 1 to 180, in the order that you would find them on a dart board. Then, you could use something like this. it asks what score you're aiming for, then tightens the random number generation range around your aimed for cell. the size of this tightened range is defined by your difficulty level so a level 10 difficulty generates a random number from range of only 20, whereas a level 5 generates a value from a range of 120 cells. Your score can't go below zero, and can't equal 1 so you have to hit an exact number to eventually reach zero. The problem here is that if you aim for 180, you'll likely miss but still get a high score because the numbers are in order. But using some sort of aim function seem more realistic I think.

I'm not sure how you would work in the "double" thing to go out, but we could probably figure it out if you arranged the cells in dart board order with double values marked out. You could adjust the different difficulty ranges to be more appropriate as well.

7. ## Re: Generating Random Numbers

Hi

Sub random()

Dim rng As Range

Set rng = Range("a1:a180")

rng.Cells(Int(Rnd * rng.Cells.Count) + 1).Select

End Sub

With this code it works however if I want to have the selected result cell and copy the result to another cell to show. What I'm trying to do is have a prize draw macro that randomly pick the cell and display the winner.

My idea is

A1 customer name
B2 points my customer have

Execute macro and display the winner on screen. Is this possible ?

8. ## Re: Generating Random Numbers

Hi Sacen,

You'll have to start a new thread with your question; forum rules.

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1