Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Random Number Question

Random Number Question

Scheduled Pinned Locked Moved C#
tutorialgame-devhelpquestionlounge
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rmeister29
    wrote on last edited by
    #1

    I am working on a school project which calls for a random number based on user input and unfortunately I cannot seem to find how to do this. My book does not offer a very good explanation of this and when I search for this online I get some very confusing results. Here is the problem in a nutshell: I am creating a math game to be used by children. They need to provide which operator they want and choose the maximum numbers to use when generating the problems. My random generator needs to be based on what the maximum numbers are. For example: User input: maxNumber1: 5 maxNumber2: 10 random generated problem: 5+10 (or any other problem using 1-5 and 1-10) I am not asking for anyone to solve my problem for me but I would appreciate a little direction as to where I can find the answer that would pertain to this scenario. Thanks in advance!

    L M 2 Replies Last reply
    0
    • R rmeister29

      I am working on a school project which calls for a random number based on user input and unfortunately I cannot seem to find how to do this. My book does not offer a very good explanation of this and when I search for this online I get some very confusing results. Here is the problem in a nutshell: I am creating a math game to be used by children. They need to provide which operator they want and choose the maximum numbers to use when generating the problems. My random generator needs to be based on what the maximum numbers are. For example: User input: maxNumber1: 5 maxNumber2: 10 random generated problem: 5+10 (or any other problem using 1-5 and 1-10) I am not asking for anyone to solve my problem for me but I would appreciate a little direction as to where I can find the answer that would pertain to this scenario. Thanks in advance!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Without negative values? I guess you should look at Random.Next(int)[^] Don't forget to only create 1 instance of Random, don't make a new one every time (ok I know it's not like it will really matter in this case, but it's still bad practice to do it)

      1 Reply Last reply
      0
      • R rmeister29

        I am working on a school project which calls for a random number based on user input and unfortunately I cannot seem to find how to do this. My book does not offer a very good explanation of this and when I search for this online I get some very confusing results. Here is the problem in a nutshell: I am creating a math game to be used by children. They need to provide which operator they want and choose the maximum numbers to use when generating the problems. My random generator needs to be based on what the maximum numbers are. For example: User input: maxNumber1: 5 maxNumber2: 10 random generated problem: 5+10 (or any other problem using 1-5 and 1-10) I am not asking for anyone to solve my problem for me but I would appreciate a little direction as to where I can find the answer that would pertain to this scenario. Thanks in advance!

        M Offline
        M Offline
        Migounette
        wrote on last edited by
        #3

        For instance: Random RandomClass = new Random(); // The Next method should be called with two arguments: the minimum value and the maximum value. int RandomNumber = RandomClass.Next(maxNumber+1, maxNumber+2);

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups