algorithmic modeling for Rhino
Hi,
Is it possible to use function System.Random.Range(i, list.length) ?
When I type System.Random I cannot access Range.
I would like just to shuffle items in a list similar to this:
for (int i = 0; i /span> alpha.Count; i++) {
string temp = alpha[i];
int randomIndex = Random.Range(i, alpha.Count);
alpha[i] = alpha[randomIndex];
alpha[randomIndex] = temp;
}
Thanks,
Petras
Tags:
Where did you find a method called Range on the Random class? I can't see it on the MSDN documentation.
It looks like I was looking at a wrong place.
Could you help me to shuffle objects in a list?
Thanks,
Petras
I usually create an array of doubles and then sort that array while also sorting the other collection. But you'd have to convert the list to an array first.
Top of my head:
public void ShuffleList<T>(List<T> list, int seed)
{
T[] array0 = list.ToArray();
double[] array1 = new double[list.Count];
Random random = new Random(seed);
for (int i = 0; i < array1.Length; i++)
array[i] = random.NextDouble();
System.Array.Sort(ref array1, ref array0);
list.Clear();
list.AddRange(array0);
}
Make chaos, take chaos ... whatever comes first.
he he
Dear David and Peter,
Thank you for the help for the chaos:)
Just one more question. How does this line work?
data.OrderBy(x => rnd.Next()).ToList();
This is a LINQ (Google that) thingy (kinda a "SQL" (kinda) type of "language"):
https://msdn.microsoft.com/en-us/library/vstudio/bb534966%28v=vs.10...
For instance if you want to find things that (a) are objects, (b) of type slider, (c) where their nickname starts with ... er ... "LordOfDarkness" and (d) put them into a List you type the following:
BTW: LINQ may be cool but is slow.
BTW: Since you are after chaos ... what about adding chaos to chaos? See attached.
BTW: Get this all-time-classic LINQ stuff from The Master Of All C# things.
Thanks for the information. Is this procedure slower than David Rutten script?
Make chaos, take chaos, skin a cat with 3 ways ... whatever comes first.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by