Quick math question

This is a discussion on Quick math question within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Ok, I wasn't sure where to post this so I'll try GD. If the mods feel it belongs in the ...

  1. #1
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728

    Quick math question

    Ok, I wasn't sure where to post this so I'll try GD. If the mods feel it belongs in the c++ forum, then thats ok.

    I am trying to write a function but am having problems with the math concept of it. What I want is to have a function return a random number based on the following four parameters: the minimum value it can be, the maximum value it can be, and a median and slope number that I'll explain in a second. Basically what I have in mind is something that resembles a bell curve function. The median number is the highest point in the curve and will be the most likely number returned by the function. Depending on how steep the slope parameter is, the lower the probability of getting a number farther away from the median. So for convenience sake, lets say that the possible values of the slope are 0%-100%. Then 99% means that it is extremely unlikely to get a number far away from the median, and you are almost guaranteed of getting the median or a number right next to the median. As the slope gets smaller, the probability of finding a number farther away increases, until you get a slope of 0% which means all numbers between the max and min are equally possible.

    An example would be something like:
    min:2 max:8 median:5 slope:75%
    has this probability which is arbitrary at the moment (doesn't have to be these exact percentages):
    return 2:3% 3:7% 4:15% 5:50% 6:15% 7:7% 8:3%

    Lately I've come across quite a few uses for something like this. I'm just looking for some time of general equation or help on how to write something small like this. Don't need code, just a quick kick in the right direction will do

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Sounds like you want a normal distribution or similar, (didn't have time to read all your requirements - leaving now).
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    You know, I always hated those long problems that they gave you in school on math tests, like, "Billy and Jane (and they always had names like that), were going camping (What? Together? With no adults? In middle school? Sickos...) and wanted to get the best deal on granola bars..." and the story goes on, but has anyone noticed, that Billy and Jane always spend hours just to save a few cents on a stupid pack of granola bars? If it tastes good buy it! And what about those problems where you have to figure out how long it's going to for the bath to fill up based on how fast water's coming in, and how fast it's going out. That really doesn't teach little kids to waste water, now does it? Yes, I know that has nothing to do with the question, but don't you think it's a valid point?

  4. #4
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Um... ok sean

    Thanks adrianxw, that is pretty much what I needed. I worked on it last night and came up with a random number generator that uses normal distribution and got it working. Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  2. Quick Question on File Names and Directories
    By Kyoto Oshiro in forum C++ Programming
    Replies: 4
    Last Post: 03-29-2002, 01:54 AM
  3. * quick question *
    By SavesTheDay in forum C Programming
    Replies: 3
    Last Post: 03-27-2002, 05:58 PM
  4. just a reaaaaaaly quick question plz help
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 03-21-2002, 10:39 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21