Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Help writing a seemingly simple algorithm

Author
Message
Suicidal Sledder
19
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 29th Nov 2015 21:55
Hey all,
Not sure why this is kicking my butt so badly. It seems simple enough but I after almost a week of on and off playing with it I can seem to get it quite right.

My algorithm will generate a number of items in an entity. For example, the number of people in a bunch of households, the number of planets orbiting a bunch of star systems, or the number of cars in a bunch of parking lots. I want the user to define 3 values called, Max, Density, and Entropy.


Max will define the maximum number of items per entity expressed as an absolute value
Density will define how numerous the items are expressed as a percentage
Entropy will define the range of items per entity expressed as a percentage

For example, I want my algorithm to generate the number of members of 100 households. User defines Max as 10, density as 50%, and entropy as 0%
50% of 10 is 5 and since there is no entropy then every house has 5 members

If user defines max as 10, density as 50%, and entropy as 100%
50% of 10 is 5, but entropy is 100 meaning my algorithm should generate a random number between 1 and 10, but heavily weighted to be closer to 5. In other words, lots of 4s, 5s, 6s, and some 1s, and 10s.

If user defines max as 5, density as 100%, entropy as 0%
Every house will have 5 members.

Sorry if this doesn't make sense... The best I could come up with is something like this:



if M = 10, D = 50 , E = 100 then the result would be a range between -5 and +5. so abs() it and the range is 0-5.
if M = 5, D = 80, E = 50 then the result would be a range of 1.5 - 4 .

I feel like I am very close. The problem here is that it doesn't quite perform correctly. I dont wants the density to to simply cap the maximum at the percentage. Like if M is 10 and D is 50 then the the maximum possible value is always 5. As is, there is no use for the density setting since all it does is reduce M by a percentage!!

If anyone has any bright ideas or maybe ever done something like this then I would appreciate it. If you need some more clarification or if this doesnt make sense let me know. I am notoriously bad at explaining myself. Thanks!!
Sadly, programming is only a hobby for me right now. As it turns out, driving a 70 ton, 7 million dollar Abrams tank requires less qualification than pecking away at a keyboard. Who\'da thunk it?
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 30th Nov 2015 06:47 Edited at: 30th Nov 2015 07:21
Try this.




Edit: This can be reduced further to:

Login to post a reply

Server time is: 2024-03-29 06:51:42
Your offset time is: 2024-03-29 06:51:42