Grasshopper

algorithmic modeling for Rhino

Hallo everyone,

In a component of mine I used a custom ICompare class to "randomly sort" a list of objects. The ICompare class is extend with a seed value that can be entered when generating it.

to compare two values a random number is generated through the following function:


rnd1 = New Random(Math.Min(value1 + Me.seed, Int32.MaxValue))
s1 = rnd1.NextDouble()
rnd2 = New Random(Math.Min(value2 + Me.seed, Int32.MaxValue))
s2 = rnd1.NextDouble()

The two values are then compared based on the generated s1, s2 values. 

This should return the same value if the ICompare seed and the value is the same.

Interestingly one my computer it works as expected but when I run it on another computer it doesn't work it replies:

1. Solution exception:Unable to sort because the IComparer.Compare() method returns inconsistent results. Either a value does not compare equal to itself, or one value repeatedly compared to another value yields different results. x: '',  x's type: 'graphVertex', IComparer: 'SpiderWebLibrary.graphElements.compare.gVrndComp'.

Any thoughts beyond the obvious?

Views: 360

Replies to This Discussion

rnd1 = New Random(Math.Min(value1 + Me.seed, Int32.MaxValue))
s1 = rnd1.NextDouble()
rnd2 = New Random(Math.Min(value2 + Me.seed, Int32.MaxValue))
s2 = rnd1.NextDouble()

Is this copied or re-typed? shouldn't s2 = rnd2.NextDouble()

hmmm, ... thx for the help, issue solved

But why is it working on my Computer? 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service