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. Rundom function

Rundom function

Scheduled Pinned Locked Moved C#
helplounge
17 Posts 11 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.
  • T Thomas Krojer

    you are to kind: you also could tell him to use the feature "object browser" with the "random" keyword :)

    I cannot remember: What did I before google?

    P Online
    P Online
    PIEBALDconsult
    wrote on last edited by
    #5

    He may have tried that with "rundom". :rolleyes: I expect he'll be back asking why it keeps giving the same value over and over.

    L 1 Reply Last reply
    0
    • P Pete OHanlon

      All can be worked out with a little bit of Google-fu. Type one thing in, 2 clicks and I got this[^]. Weak in the way of the Google are you.

      I'm not a stalker, I just know things. Oh by the way, you're out of milk.

      Forgive your enemies - it messes with their heads

      My blog | My articles | MoXAML PowerToys | Onyx

      T Offline
      T Offline
      treuveni
      wrote on last edited by
      #6

      I don't want to use the random class. i want to ceate this by my own.

      P R realJSOPR B 4 Replies Last reply
      0
      • T treuveni

        I don't want to use the random class. i want to ceate this by my own.

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #7

        Don't you think you should have stated that in your original question then? We don't read minds.

        I'm not a stalker, I just know things. Oh by the way, you're out of milk.

        Forgive your enemies - it messes with their heads

        My blog | My articles | MoXAML PowerToys | Onyx

        1 Reply Last reply
        0
        • T treuveni

          Hi, I'm trying to create a function that gets 2 numbers and returns a random number between those two number. help please

          D Offline
          D Offline
          David1987
          wrote on last edited by
          #8

          You'll need a source of randomness and a way to map the output of that source to numbers between your two inputs. If you want the result to be uniformly chosen from the specified interval, you shouldn't use modulo - that would result in a "first part" where the numbers have a slightly higher chance of being picked then the ones in the "second part". edit: Ok I just saw your post that you don't want to use the random class, then look up Mersenne Twister and implement that if you want it to be useful, or any simple PRNG if you want something as bad as System.Random or worse.

          1 Reply Last reply
          0
          • T treuveni

            I don't want to use the random class. i want to ceate this by my own.

            R Offline
            R Offline
            riced
            wrote on last edited by
            #9

            Try this: Simple Random Number Generation[^] And, as Peter said, why did you not say this in the original post since it would avoid people telling you to look it up in help.

            Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis The only valid measurement of code quality: WTFs/minute.

            1 Reply Last reply
            0
            • P PIEBALDconsult

              He may have tried that with "rundom". :rolleyes: I expect he'll be back asking why it keeps giving the same value over and over.

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #10

              you're an optimist. I think there is no running code yet. :)

              Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

              1 Reply Last reply
              0
              • T treuveni

                I don't want to use the random class. i want to ceate this by my own.

                realJSOPR Offline
                realJSOPR Offline
                realJSOP
                wrote on last edited by
                #11

                treuveni wrote:

                I don't want to use the random class.

                i want to ceate this by my own

                Well why didn't you f*ckin say that in your original message? How are we supposed to read your simple little mind when it generates almost no electrical energy on its own?

                ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                -----
                You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                -----
                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                T 1 Reply Last reply
                0
                • realJSOPR realJSOP

                  treuveni wrote:

                  I don't want to use the random class.

                  i want to ceate this by my own

                  Well why didn't you f*ckin say that in your original message? How are we supposed to read your simple little mind when it generates almost no electrical energy on its own?

                  ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                  -----
                  You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                  -----
                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                  T Offline
                  T Offline
                  treuveni
                  wrote on last edited by
                  #12

                  John Simmons / outlaw programmer wrote:

                  Well why didn't you f*ckin say that in your original message? How are we supposed to read your simple little mind when it generates almost no electrical energy on its own?

                  f*ck you

                  1 Reply Last reply
                  0
                  • T treuveni

                    Hi, I'm trying to create a function that gets 2 numbers and returns a random number between those two number. help please

                    A Offline
                    A Offline
                    ankitjoshi24
                    wrote on last edited by
                    #13

                    Just use the Sytem.Random class, assign random numbers to two integer variables and in the if statement make sure that you create another random number by checking the statement to be between the first two random numbers. but you need to make sure if both are positive or one is negative. You will get help on this over here: - http://www.javadocexamples.com/java/util/java.util.Random.html[^] Javadoc is the most helpful thing for any java developers. So always visit javadoc and try to find your answers

                    P G 2 Replies Last reply
                    0
                    • T treuveni

                      I don't want to use the random class. i want to ceate this by my own.

                      B Offline
                      B Offline
                      Bernhard Hiller
                      wrote on last edited by
                      #14

                      public int GetRandomNumber()
                      {
                      //this must be random because it was determined by fair dice rolling
                      return 3;
                      }

                      1 Reply Last reply
                      0
                      • A ankitjoshi24

                        Just use the Sytem.Random class, assign random numbers to two integer variables and in the if statement make sure that you create another random number by checking the statement to be between the first two random numbers. but you need to make sure if both are positive or one is negative. You will get help on this over here: - http://www.javadocexamples.com/java/util/java.util.Random.html[^] Javadoc is the most helpful thing for any java developers. So always visit javadoc and try to find your answers

                        P Offline
                        P Offline
                        Pete OHanlon
                        wrote on last edited by
                        #15

                        A couple of points. First of all, you point him to System.Random, and then you send him over to the Java documentation - this is an inconsistent approach. Secondly, he's stated elsewhere in the thread that he wants to roll his own random implementation (it's probably homework). Finally, resources like MSDN are not always the best solution - they tend to be written by tech writers rather than battle hardened developers working with the technologies out in the trenches.

                        I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                        Forgive your enemies - it messes with their heads

                        My blog | My articles | MoXAML PowerToys | Onyx

                        A 1 Reply Last reply
                        0
                        • A ankitjoshi24

                          Just use the Sytem.Random class, assign random numbers to two integer variables and in the if statement make sure that you create another random number by checking the statement to be between the first two random numbers. but you need to make sure if both are positive or one is negative. You will get help on this over here: - http://www.javadocexamples.com/java/util/java.util.Random.html[^] Javadoc is the most helpful thing for any java developers. So always visit javadoc and try to find your answers

                          G Offline
                          G Offline
                          GlobX
                          wrote on last edited by
                          #16

                          ankitjoshi24 wrote:

                          Javadoc is the most helpful thing for any java developers. So always visit javadoc and try to find your answers

                          This is a C# forum... huh?

                          1 Reply Last reply
                          0
                          • P Pete OHanlon

                            A couple of points. First of all, you point him to System.Random, and then you send him over to the Java documentation - this is an inconsistent approach. Secondly, he's stated elsewhere in the thread that he wants to roll his own random implementation (it's probably homework). Finally, resources like MSDN are not always the best solution - they tend to be written by tech writers rather than battle hardened developers working with the technologies out in the trenches.

                            I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                            Forgive your enemies - it messes with their heads

                            My blog | My articles | MoXAML PowerToys | Onyx

                            A Offline
                            A Offline
                            ankitjoshi24
                            wrote on last edited by
                            #17

                            I apologize. My bad.... And I agree to the MSDN is not always the best but for beginners, it does provide a good start.... After understanding the codes on MSDN they can always try and improvise...

                            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