Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't really randomize a Enumerable unless you convert it to an array first, because an enumerator by definition gets 1 value at a time, token by token. </p> <p>So, if I understand correctly, I would do something like this...</p> <ol> <li>Convert list_of_is to an array</li> <li>For each j in list_of_js</li> <li>Loop through list_of_is performing Fisher-Yates shuffle</li> <li>Loop through list_of_is and do f(j,i) where i is the current index in the shuffle</li> </ol> <p>Here's a quick example, I hope this helps (sorry fixed some errors)</p> <pre><code>using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace ConsoleApplication1 { class Program { static IEnumerable&lt;char&gt; list_of_is = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g'}; static IEnumerable&lt;char&gt; list_of_js = new char[] { 'x', 'y', 'z' }; static void Main(string[] args) { foreach (string result in Randomize()) Debug.Write(result); } public static IEnumerable&lt;String&gt; Randomize() { char[] random_is = list_of_is.ToArray(); int jCount = list_of_js.Count(); Random r = new Random(); // foreach j foreach(char j in list_of_js) { // create a random ordering of is for (int i = random_is.Length - 1; i &gt;= 0; i--) { int x = r.Next(0, i); // swap char temp = random_is[x]; random_is[x] = random_is[i]; random_is[i] = temp; } // now evaluate the random pairs foreach(Char i in random_is) yield return String.Format("{0}{1} ", Char.ToUpper(i), j); } } } } </code></pre> <p>outputs</p> <pre><code>Gx Cx Ex Bx Fx Ax Dx Dy By Fy Ay Cy Gy Ey Bz Az Gz Cz Fz Ez Dz </code></pre> <p><strong>Edit:</strong> Actually, it just hit me that your pseudocode doesn't quite seem right. You are generating 3 random arrays of 7 values.. and then wanting to output pairs of X,Y,Z for each of the random arrays. It seems like yoou would need 3 * 7 * 3 = 63 ouputs then..</p> <p>Therefore, this may be more accurate:</p> <pre><code>public static IEnumerable&lt;String&gt; Randomize() { char[] random_is = list_of_is.ToArray(); int jCount = list_of_js.Count(); Random r = new Random(); // foreach j for (int random = 0; random &lt; jCount; random++) { // create a random ordering of is for (int i = random_is.Length - 1; i &gt;= 0; i--) { int x = r.Next(0, i); // swap char temp = random_is[x]; random_is[x] = random_is[i]; random_is[i] = temp; } // now evaluate the random pairs foreach (Char i in random_is) foreach(Char j in list_of_js) yield return String.Format("{0}{1} ", Char.ToUpper(i), j); } } </code></pre> <p>And it outputs:</p> <pre><code>Cx Cy Cz Gx Gy Gz Dx Dy Dz Bx By Bz Fx Fy Fz Ax Ay Az Ex Ey Ez Bx By Bz Cx Cy Cz Fx Fy Fz Ax Ay Az Ex Ey Ez Dx Dy Dz Gx Gy Gz Cx Cy Cz Ax Ay Az Bx By Bz Gx Gy Gz Fx Fy Fz Ex Ey Ez Dx Dy Dz </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload