Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List.Shuffle shuffles nested lists incorrectly #54

Closed
dimven opened this issue Apr 20, 2017 · 6 comments
Closed

List.Shuffle shuffles nested lists incorrectly #54

dimven opened this issue Apr 20, 2017 · 6 comments
Labels
DesignScript DesignScript improvements Nodes Nodal improvement UX UX improvement

Comments

@dimven
Copy link

dimven commented Apr 20, 2017

Dynamo version

ever since 0.82:
http://dynamobim.org/forums/topic/random-list-of-lists/

Operating system

Windows 7

What did you do?

Ran some nested lists through a list-shuffle node

What did you expect to see?

Uniquely shuffled sub-lists

What did you see instead?

Identically shuffled lists:

revit_2017-04-20_09-25-25

This was reported previously and ignored:
DynamoDS/Dynamo#5977

@mjkkirschner
Copy link
Member

@dimven yep yep! check out the implementation:
https://github.com/DynamoDS/Dynamo/blob/master/src/Libraries/CoreNodes/List.cs#L1161

the new random should be moved to the class level for the behavior you are expecting as it's set to a seed based on the clock. When called all at once we get the same random numbers.

@ke-yu what do you think?

@dimven
Copy link
Author

dimven commented Apr 20, 2017

Sounds good to me. Alternatively, we can follow this SO:
http://stackoverflow.com/questions/1785744/how-do-i-seed-a-random-class-to-avoid-getting-duplicate-random-values

and give it a unique seed every time. Seems to work well:

revit_2017-04-20_09-54-00

As a side note, since lists are the backbone of every Dynamo graph and you'd usually use at least a few list methods in every graph, has the team considered replacing some of those LINQ calls for the sake of memory efficiency?

@dimven
Copy link
Author

dimven commented Apr 20, 2017

Not sure if this is a good example, but the below seems to be about twice as fast:

static IList Shuffle2(IList list)
{
    var rng = new Random(Guid.NewGuid().GetHashCode());
    int[] vals = new int[list.Count];
    object[] data = new object[list.Count];
    for (int i = 0;
         i < list.Count;
         i++)
    {
    	vals[i] = rng.Next();
    	data[i] = list[i];
    }
    Array.Sort(vals, data);
    return (IList)data;
}

image

Unless I'm just pushing the burden off to somewhere else, like the marshaller...

@ke-yu
Copy link

ke-yu commented Apr 20, 2017

@mjkkirschner we'll still get then same shuffled list each time open dynamo (will we?) if yes then using guid's hashcode or system tick count as see would be more "random"

@firas007noori
Copy link

Hi, I have no knowledge in Python, and I saw the solution for sublist shuffle here, and I used it, I thank you all, it worked for 2 days an suddenly the letter (a) in it turn into blue an it all stop working on one laptop, the other!! is still working normally with the letter (a) is not blue!!??
Any help is really appreciated, thanks in advance
Capture of error in python

@Amoursol Amoursol transferred this issue from DynamoDS/Dynamo Mar 31, 2020
@Amoursol Amoursol added DesignScript DesignScript improvements Nodes Nodal improvement UX UX improvement labels Mar 31, 2020
@Amoursol
Copy link
Contributor

This has now been fixed in Dynamo 2.10: https://dynamobim.org/dynamo-core-2-10-release/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DesignScript DesignScript improvements Nodes Nodal improvement UX UX improvement
Projects
Status: Done
Development

No branches or pull requests

5 participants