+ Reply to Thread
Results 1 to 8 of 8

Generating Random Numbers

  1. #1
    Registered User
    Join Date
    01-20-2014
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    59

    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?

    Thanks in advance

  2. #2
    Forum Contributor
    Join Date
    04-25-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    150

    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. #3
    Registered User
    Join Date
    01-20-2014
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    59

    Re: Generating Random Numbers

    Quote Originally Posted by djdjdj View Post
    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. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    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.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Registered User
    Join Date
    01-20-2014
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    59

    Re: Generating Random Numbers

    Quote Originally Posted by Richard Buttrey View Post
    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. #6
    Forum Contributor
    Join Date
    04-25-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    150

    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.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    02-24-2014
    Location
    New Zealand
    MS-Off Ver
    Excel 2013
    Posts
    4

    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. #8
    Forum Contributor
    Join Date
    04-25-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: Generating Random Numbers

    Hi Sacen,

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

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Generating Random numbers that will sum to 1 specific value?
    By zr11 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-24-2019, 10:08 AM
  2. Generating random numbers
    By softik in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-31-2013, 01:52 AM
  3. Generating a list of Random numbers of random length...
    By Growl in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-19-2013, 12:10 PM
  4. Generating a Random Number of Random Numbers
    By Garrus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2010, 09:39 AM
  5. [SOLVED] Generating Random Number from a set of numbers
    By CalsLib in forum Excel General
    Replies: 3
    Last Post: 03-17-2006, 12:27 PM

Bookmarks

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