AND and OR statement...loop with several conditions

stefdelecstefdelec Member, PRO Posts: 146
edited August 2015 in Working with GS (Mac)

Hi,

I am really struggling with this.

I need to generate 2 pairs of attributes.
attr1=random(-1;1)
attr2=random(-1;1)
attr3=random(-1;1)
attr4=random(-1;1)

attr1 and attr2: I need at least one of them to be different from 0.
attr3 and attr4: I need at least one of them to be different from 0.

AND I need (attr1;attr2) different from (attr3;attr4).

I am using a loop atm:

while all : attr1 = 0 and attr 2= 0 => random both of them.

Any idea?

Thanks,

Stéphane.

Comments

  • ArmellineArmelline Member, PRO Posts: 5,421

    AND I need (attr1;attr2) different from (attr3;attr4).

    Does this mean attr1 must be different from attr3 and attr2 must be different from attr4, or does it mean that attr1 and attr2 must be different from attr3 and attr3?

    i.e.

    1,0 / 1,-1 would be okay?
    or would it have to be 1,0 / -1,1 or something similar?

    In other words, is it the whole pairings that must be different?

  • stefdelecstefdelec Member, PRO Posts: 146

    The pairing must be different

    1;1 /1;1 not ok
    1;1/1;0 ok.
    1;1; / 1;-1 ok.

    Am I clear?

  • ArmellineArmelline Member, PRO Posts: 5,421

    Wow this was quite an interesting one to solve.

    I'm sure there's a simpler way of going about this, but here's what I came up with. There are a lot of conditions that need to be met when generating the numbers.

    Looking forward to seeing how someone cleverer does it in a more simple way!

    I've specifically avoided loops as they tend to run slower than using conditions. It can almost certainly be done more cleanly using loops, but I'd be surprised if it can be done quicker.

  • stefdelecstefdelec Member, PRO Posts: 146
    edited August 2015

    Hum thanks a lot!I didn't know rules were faster than loop....!

    If someone has another idea?

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    Are we dealing with decimals here?

  • ArmellineArmelline Member, PRO Posts: 5,421

    @stefdelec said:
    Hum thanks a lot!I didn't know rules were faster than loop....!

    If something can be done in a single pass, it's almost always better to do it that way. My solution may look a little complicated, but it's really not - just read the rule names and you'll see exactly what it'd doing (if your screen is smaller and they're getting cut off, just copy/paste them into a note or something).

  • stefdelecstefdelec Member, PRO Posts: 146

    Nop! No decimal!

    Thansk, I ve checked your rules! SOunds good!

Sign In or Register to comment.