I have a list of numbers. With C# I want to remove the numbers gradually randomly when numbers come closer to a target number.
I now how to do something with a target number in Python
def randomIntegerVa(startVa,endVa,targetVa=None):
if targetVa!=None:
randomIntegerVa=round(r.triangular(startVa,endVa,targetVa))
else:
randomIntegerVa=r.randint(startVa,endVa)
return randomIntegerVa
I was thinking about something with divide or the remainder to increase the change a number is removed. But that does not sound that smart because it has nothing to do with ‘randomness.’
Maybe I should first remap-ly randomly remove.
A. Remove randomly x-amount of items.
B. Increase change of removal when closer to target number.
1# Question: Is MathNet a thing in C#?
It does not seem like it.
I entered ‘using MathNet;’
I am aware of that function. To what you are pointing to? A triangular function or something like that? Is it something in the examples on that page?
However, you made me think.
When a values comes closer to a target number a sub list of 0’s and 1’s should be increase or there should be compared to a minimum and maximum closest to the target number a specific amount of 0’s and 1’s by which randomly an item is choosing selecting or deselecting a value of my list.
So.
values 0, 2, 3, 4, 9, 22, 28
target 3
max to target is 28
value 3 makes [0, 1, 1, 1, 1] => 0 is 20% of the time
value 28 makes [0, 0, 0, 1, 0] => 0 is 80% of the time
Or something like that.
But you were pointing to a random.triangular or something?
Does it exist?
you find the current phyton implementation of the random triangular function here
Line 507 onwards…
def triangular(self, low=0.0, high=1.0, mode=None):
"""Triangular distribution.
Continuous distribution bounded by given lower and upper limits,
and having a given mode value in-between.
http://en.wikipedia.org/wiki/Triangular_distribution
"""
u = self.random()
try:
c = 0.5 if mode is None else (mode - low) / (high - low)
except ZeroDivisionError:
return low
if u > c:
u = 1.0 - u
c = 1.0 - c
low, high = high, low
return low + (high - low) * _sqrt(u * c)
the comments show the wikipedia link for background info.
… translate those 6 lines of code into (12? ) c#
kind regards -tom
Hello
From what I understand if mode is None it means there is no value so by default mode is set to middle => 0.5. But Random in Python is surely between 0 and 1. So why I use Random.NextDouble()
Here for the script I count how many value are on the interval in order to test the distribution. It seems OK.
in the phyton code, the low, high, mode are optional parameters, set to 0,1,None:
`(self, low=0.0, high=1.0, mode=None)
similar is possible in c#, dependent on wether it is a object type (check for “null”) or a value type. (check for the topic “nullable”, or for Double.NaN… ) (double low = 0.0, double high = 1.0, double mode = Double.NaN)
in the context of Rhino, you should use
[RhinoMath.UnsetValue] (https://developer.rhino3d.com/api/RhinoCommon/html/F_Rhino_RhinoMath_UnsetValue.htm) instead of NaN