<div dir="ltr">Hi David,<div><br></div><div>Thank you so much for your reply. I know the thing is a visual nightmare at the moment and needs a little aesthetic touch up. Sorry! </div><div><br></div><div>These are incredibly helpful suggestions and getting me to think about this a lot deeper.</div><div><br></div><div>The only issue with the array, while it would be easier, is that 1. It seems like I could still have some over lap since my images are 2x3 % in eprime and 2. ideally I would like to still be able to use the same x coordinate for two images just so long as they don't overlap (they are far enough apart on the y).</div><div><br></div><div>So it's really tricky since I need to consider a range of coordinates when I place an image to insure they do not overlap. </div><div><br></div><div>I like the idea of the 2 dimensional array (sounds tricky) cause that would solve #1 but not sure how to get around #2 and ensuring they don't overlap + or - 2 or 3 values.</div><div><br></div><div>Thanks again so much for the help!<br><br>On Monday, August 4, 2014 2:01:56 PM UTC-5, McFarlane, David wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Tara,
<br>
<br>Wow, that Loop While statement just hurts my eyes!  When something 
<br>gets that complicated, I would at least try to format it better for 
<br>readability (indentation and the "_" continuation character are your 
<br>friends here), or better yet find some way to restructure the code so 
<br>as to avoid such a long expression.  E.g., if you used some arrays 
<br>instead of simple variables then you could use a loop or two to run 
<br>through all those tests that appear explicitly in your While expression.
<br>
<br>So I do not know if something goes wrong with your code per se.  But 
<br>your approach here reminds me of a bogosort (see 
<br><a href="http://en.wikipedia.org/wiki/Bogosort" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FBogosort\46sa\75D\46sntz\0751\46usg\75AFQjCNGgeX9DQ-nEOqL2bNevKUVQsWscfg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FBogosort\46sa\75D\46sntz\0751\46usg\75AFQjCNGgeX9DQ-nEOqL2bNevKUVQsWscfg';return true;">http://en.wikipedia.org/wiki/<wbr>Bogosort</a> ), and it may suffer from the 
<br>same problem.  Even with no errors in the code, the code must find a 
<br>solution *by chance*, and *by chance* that may take many tries.  That 
<br>may work well enough for small problems, but as the proportion of 
<br>solutions in the problem space gets smaller this approach takes 
<br>longer and longer to find one.  In particular, perhaps for 3 
<br>coordinates your "bogosort" code could quickly find a solution, but 
<br>for 4 images it just takes a lot longer to find one *by 
<br>chance*.  (PST's own "No Repeats on Consecutive Trials" examples, 
<br>download from their website, suffer the same problem.)
<br>
<br>I do not like algorithms that work by chance, so I avoid them 
<br>whenever possible.  So first let's restate your problem, and see what 
<br>we can do.
<br>
<br>You want to find 4 unique, randomly chosen x values from a pool of 7 
<br>values, and 4 unique, randomly chosen y values from a pool of 23 
<br>values.  IOW, you want to pick 4 x values randomly without 
<br>replacement from the range [36, 42], and 4 y values randomly without 
<br>replacement from the range [38, 62].  Did I get that right?
<br>
<br>Ideally, you would follow David V's advice, make a nested List with 
<br>all possible (x, y) pairs and just pick from that (Random, without 
<br>replacement).  That should involve 7 x 23 = 161 rows, which would not 
<br>be too much trouble, and Excel would make it even easier to construct 
<br>such a List.  Alternatively, you might use two nested Lists, one for 
<br>all the x values and another for all the y values, each Random 
<br>(without replacement) and pick from those.
<br>
<br>But if you like inline code, I might start by making a couple arrays 
<br>to hold my pools of x & y values:
<br>
<br>     Const xPoolSize as Integer = 7, xPool1 as Integer = 36
<br>     Const yPoolSize as Integer = 23, yPool1 as Integer = 38
<br>     Dim i as Integer
<br>     Dim xPool( 1 to xPoolSize ) as Integer
<br>     Dim yPool( 1 to yPoolSize ) as Integer
<br>     xPool(1) = xPool1
<br>     For i = 2 to xPoolSize
<br>         xPool(i) = xPool(i-1) + 1
<br>     Next i
<br>     yPool(1) = yPool1
<br>     For i = 2 to yPoolSize
<br>         yPool(i) = yPool(i-1) + 1
<br>     Next i
<br>
<br>With a little trouble you could compact that code even better by 
<br>using a 2-dimensional array for x & y together, although then the 
<br>next step would not work.  I leave that as an exercise.
<br>
<br>Next, just shuffle these arrays.  VBA/E-Basic provides a command just 
<br>for this (but only for 1-dimensional arrays, sigh):
<br>
<br>     RandomizeArray xPool
<br>     RandomizeArray yPool
<br>
<br>
<br>You may find RandomizeArray documented in the E-Basic Help facility.
<br>
<br>Now you may simply pick the first 4 values from the xPool & yPool 
<br>arrays to construct your coordinates.
<br>
<br>Does that look like it will work?  What have I missed?
<br>
<br>-----
<br>David McFarlane
<br>E-Prime training 
<br>online:  <a href="http://psychology.msu.edu/Workshops_Courses/eprime.aspx" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fpsychology.msu.edu%2FWorkshops_Courses%2Feprime.aspx\46sa\75D\46sntz\0751\46usg\75AFQjCNHhJVD3mCfXKdywfB5AgKLPu1OSJg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fpsychology.msu.edu%2FWorkshops_Courses%2Feprime.aspx\46sa\75D\46sntz\0751\46usg\75AFQjCNHhJVD3mCfXKdywfB5AgKLPu1OSJg';return true;">http://psychology.msu.edu/<wbr>Workshops_Courses/eprime.aspx</a>
<br>Twitter:  @EPrimeMaster (<a href="https://twitter.com/EPrimeMaster" target="_blank" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Ftwitter.com%2FEPrimeMaster\46sa\75D\46sntz\0751\46usg\75AFQjCNHlT7nwYBmELwRxV4Xn5GW-sG9EKw';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Ftwitter.com%2FEPrimeMaster\46sa\75D\46sntz\0751\46usg\75AFQjCNHlT7nwYBmELwRxV4Xn5GW-sG9EKw';return true;">https://twitter.com/<wbr>EPrimeMaster</a>)
<br>
<br>/----
<br>Stock reminder:  1) I do not work for PST.  2) You may reach PST's 
<br>trained staff (and other support facilities) at 
<br><a href="https://support.pstnet.com" target="_blank" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fsupport.pstnet.com\46sa\75D\46sntz\0751\46usg\75AFQjCNF5BfukPzW6lq7UCweMsMu7_9wJEQ';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fsupport.pstnet.com\46sa\75D\46sntz\0751\46usg\75AFQjCNF5BfukPzW6lq7UCweMsMu7_9wJEQ';return true;">https://support.pstnet.com</a> .  3) If you do get an answer from PST 
<br>staff, please extend the courtesy of posting their reply back here 
<br>for the sake of others.
<br>\----
<br>
<br>
<br>At 8/1/2014 05:43 PM Friday, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="kHnIImrTePMJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">tamis...@gmail.com</a> wrote:
<br>>Thanks for your response David. That is what I was afraid of. Eprime 
<br>>support said it should work in theory, but seems as though it keeps 
<br>>getting stuck when I add in the forth image. I am trying to list all 
<br>>the combinations as well, it is just proving to be a huge task, for 
<br>>there are an enormous amount of possible combinations.
<br>>
<br>>I was hoping that this would make coding much quicker and truly random.
<br>>
<br>>Tara
<br>>
<br>>On Friday, August 1, 2014 12:54:35 PM UTC-5, Vinson, David: UCL wrote:
<br>>I suspect you didn't get any replies before due the impressively 
<br>>complicated set of OR statements in that loop. I suspect the problem 
<br>>is there somewhere but imagine it world be a nightmare to track it 
<br>>down. My guess is the loop never exits, whether due to an error or 
<br>>impossible constraints.
<br>>
<br>>What if instead you enumerated the possible legal combinations of 
<br>>positions in a nested List and then just sampled one of them per trial?
<br>>
<br>>Good luck,
<br>>David V
<br>>
<br>>----- Reply message -----
<br>>From: "<a>tamis...@gmail.com</a>" <<a>tamis...@gmail.com</a>>
<br>>To: "<a>e-p...@googlegroups.com</a>" <<a>e-p...@googlegroups.com</a>>
<br>>Subject: Help with Randomization of Non-Overlapping Images
<br>>Date: Fri, Aug 1, 2014 6:30 pm
<br>>
<br>>
<br>>
<br>>Does anyone have any suggestions on this? I'm stuck on this and 
<br>>eprime support directed me here.
<br>>
<br>>Tara
<br>>
<br>>On Monday, July 28, 2014 3:43:33 PM UTC-5, Tara Miskovich wrote:
<br>>Hello,
<br>>
<br>>I am working on having 4 images randomly places within a rectangular 
<br>>region without overlapping. I wrote the code below, and it appears 
<br>>to be working with up to Image 3 added, but when I add in the forth 
<br>>image the program freezes. I am hoping for some guidance with what 
<br>>to try next or how to get past this. Here is the code I wrote to 
<br>>randomize the x and y location for each image.
<br>>
<br>>Thanks!
<br>>Tara
<br>>
<br>>Dim x1 As Integer
<br>>Dim x2 As Integer
<br>>Dim x3 As Integer
<br>>Dim x4 As Integer
<br>>Dim y1 As Integer
<br>>Dim y2 As Integer
<br>>Dim y3 As Integer
<br>>Dim y4 As Integer
<br>>
<br>>x1 = random(36, 42)
<br>>y1 = random(38, 60)
<br>>
<br>>Do
<br>>x2 = random(36, 42)
<br>>y2 = random(38, 60)
<br>>x3 = random(36, 42)
<br>>y3 = random(38, 60)
<br>>x4 = random(36, 42)
<br>>y4 = random(38, 60)
<br>>
<br>>
<br>>Loop While (x2 = x1 Or x2 = x1 + 1 Or x2 = x1+2 Or x2 = x1 - 1 Or x2 
<br>>= x1 - 2 _
<br>>And y2 = y1 Or y2 = y1 + 1 Or y2 = y1 + 2 Or y2 = y1 + 3 Or y2 = y1 
<br>>- 1 Or y2 = y1 - 2 Or y2 = y1 - 3)_
<br>>Or (x3 = x1 Or x3 = x1 + 1 Or x3 = x1+2 Or x3 = x1 - 1 Or x3 = x1 - 2 _
<br>>And y3 = y1 Or y3 = y1 + 1 Or y3 = y1 + 2 Or y3 = y1 + 3 Or y3 = y1 
<br>>- 1 Or y3 = y1 - 2 Or y3 = y1 - 3)_
<br>>Or (x3 = x2 Or x3 = x2 + 1 Or x3 = x2+2 Or x3 = x2 - 1 Or x3 = x2 - 2 _
<br>>And y3 = y2 Or y3 = y2 + 1 Or y3 = y2 + 2 Or y3 = y2 + 3 Or y3 = y2 
<br>>- 1 Or y3 = y2 - 2 Or y3 = y2 - 3)_
<br>>or (x4 = x1 Or x4 = x1 + 1 Or x4 = x1+2 Or x4 = x1 - 1 Or x4 = x1 - 2 _
<br>>And y4 = y1 Or y4 = y1 + 1 Or y4 = y1 + 2 Or y4 = y1 + 3 Or y4 = y1 
<br>>- 1 Or y4 = y1 - 2 Or y4 = y1 - 3)_
<br>>Or (x4 = x2 Or x4 = x2 + 1 Or x4 = x2 + 2 Or x4 = x2 - 1 Or x4 = x2 - 2 _
<br>>And y4 = y2 Or y4 = y2 + 1 Or y4 = y2 + 2 Or y4 = y2 + 3 Or y4 = y2 
<br>>- 1 Or y4 = y2 - 2 Or y4 = y2 - 3)_
<br>>Or (x4 = x3 Or x4 = x3 + 1 Or x4 = x3 + 2 Or x4 = x3 - 1 Or x4 = x3 - 2 _
<br>>And y4 = y3 Or y4 = y3 + 1 Or y4 = y3 + 2 Or y4 = y3 + 3 Or y4 = y3 
<br>>- 1 Or y4 = y3 - 2 Or y4 = y3 - 3)
<br>>
<br>>c.SetAttrib "x1", x1
<br>>c.SetAttrib "x2", x2
<br>>c.SetAttrib "x3", x3
<br>>c.SetAttrib "x4", x4
<br>>c.SetAttrib "y1", y1
<br>>c.SetAttrib "y2", y2
<br>>c.SetAttrib "y3", y3
<br>>c.SetAttrib "y4", y4
<br>
<br></blockquote></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups "E-Prime" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:e-prime+unsubscribe@googlegroups.com">e-prime+unsubscribe@googlegroups.com</a>.<br />
To post to this group, send email to <a href="mailto:e-prime@googlegroups.com">e-prime@googlegroups.com</a>.<br />
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/e-prime/dec96210-911d-40dd-a0a3-06a6afd97695%40googlegroups.com?utm_medium=email&utm_source=footer">https://groups.google.com/d/msgid/e-prime/dec96210-911d-40dd-a0a3-06a6afd97695%40googlegroups.com</a>.<br />
For more options, visit <a href="https://groups.google.com/d/optout">https://groups.google.com/d/optout</a>.<br />