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. A statistical random function

A statistical random function

Scheduled Pinned Locked Moved C#
helplounge
4 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.
  • M Offline
    M Offline
    Madmaximus
    wrote on last edited by
    #1

    Hi, I am looking for a statistical random function that would allow me to supply the mean, min and max values. Something like: Double mean = 3; Double min = 1; Double max = 10; Double d = GenNext () Any help would be appreciated. :-D

    C 1 Reply Last reply
    0
    • M Madmaximus

      Hi, I am looking for a statistical random function that would allow me to supply the mean, min and max values. Something like: Double mean = 3; Double min = 1; Double max = 10; Double d = GenNext () Any help would be appreciated. :-D

      C Offline
      C Offline
      CWIZO
      wrote on last edited by
      #2

      I don't know what "mean" would be ... but have you looked at the Random class? Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

      M D 2 Replies Last reply
      0
      • C CWIZO

        I don't know what "mean" would be ... but have you looked at the Random class? Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

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

        Thanks for reply. Sorry for the confusion but here is the definition. Mean: The average of a set of N numbers. Yes I have, the best I could come up with is this: double h; double avg = 3.0, max = 10.0, min = 1.0; Random RandomClass = new Random (10); h = (- System.Math.Log(RandomClass.NextDouble())) * (avg - min); But this does not help with making sure the value doesn’t go over the max.

        1 Reply Last reply
        0
        • C CWIZO

          I don't know what "mean" would be ... but have you looked at the Random class? Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

          D Offline
          D Offline
          Dan Neely
          wrote on last edited by
          #4

          CWIZO wrote:

          I don't know what "mean" would be ... but have you looked at the Random class?

          Mean is the average ((val1 + val2 + .. valN-1 + valN)/N ) value. Random has a designed mean of (MinVal+MaxVal)/2. To do what the OP wants where the mean could be located elsewhere would need a way to define the relative distribution. For the general implementation you'd need a parameter on the line of f(x) = where F(x) is defined over the range min..max and has a global maxima at mean. F(x) would scale the random value given a random value R. you'd return K defined that Integral(f(k), min value,k) = R. Integral f(x) would need scaled to normalize the return. For a specfic distribution you could try hardcoding it instead of taking a function as aparameter. You could try examing (large) 3rd party math libraries, but I suspect this is something that you'll need to write yourself. All of this is off the top of my head, and I don't know how to do the implementation.

          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