Problem about rands use

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem about rands use

ashuan
Hello,

I have a group of 3D objects.
Each of one have a different and random configuration.

For this, i use rands like that :
   random_vect=rands(1,40,(nbCriterias1*nbCriterias2));

everything went well until i try to use 3 configurations of rands like this
:
   random_vect=rands(1,40,(nbCriterias1*nbCriterias2));
   random_vect=rands(10,10,(nbCriterias1*nbCriterias2));
   random_vect=rands(7,12,(nbCriterias1*nbCriterias2));

I have do a switch with cumulated if like that :
    min_aleat = 1;
    max_aleat = 40;
    random_vect=[];
    if (opengrid == "S")
    { // case S: full random
        min_aleat = 1;
        max_aleat = 40;
    } else {
        if (opengrid == "M")
        {   // case M: no random
            min_aleat = 10;
            max_aleat = 10;  
        } else { // case L: little random
            min_aleat = 7;
            max_aleat = 12;  
        }
    }
     random_vect=rands(min_aleat,max_aleat,(nbCriterias1*nbCriterias2));

my ifs are ok, i've control there with echo instruction.

The pb are, each time, i have the same rands response.
It didn't look about my criterias even if i replace my variable by direct
number.

Do you understand where i have make a mistake ?



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Problem about rands use

nophead
You can modify variables in OpenSCAD. The values defined in the branches of the if only last until the closing brace.

You need something like this:

min_aleat = opengrid == "S" ? 1 :
                  opengrid == "M" ? 10 : 7;


On 20 October 2017 at 16:47, ashuan <[hidden email]> wrote:
Hello,

I have a group of 3D objects.
Each of one have a different and random configuration.

For this, i use rands like that :
   random_vect=rands(1,40,(nbCriterias1*nbCriterias2));

everything went well until i try to use 3 configurations of rands like this
:
   random_vect=rands(1,40,(nbCriterias1*nbCriterias2));
   random_vect=rands(10,10,(nbCriterias1*nbCriterias2));
   random_vect=rands(7,12,(nbCriterias1*nbCriterias2));

I have do a switch with cumulated if like that :
    min_aleat = 1;
    max_aleat = 40;
    random_vect=[];
    if (opengrid == "S")
    { // case S: full random
        min_aleat = 1;
        max_aleat = 40;
    } else {
        if (opengrid == "M")
        {   // case M: no random
            min_aleat = 10;
            max_aleat = 10;
        } else { // case L: little random
            min_aleat = 7;
            max_aleat = 12;
        }
    }
     random_vect=rands(min_aleat,max_aleat,(nbCriterias1*nbCriterias2));

my ifs are ok, i've control there with echo instruction.

The pb are, each time, i have the same rands response.
It didn't look about my criterias even if i replace my variable by direct
number.

Do you understand where i have make a mistake ?



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Problem about rands use

nophead
You can't modify variables in OpenSCAD. The values defined in the branches of the if only last until the closing brace.

You need something like this:

min_aleat = opengrid == "S" ? 1 :
                  opengrid == "M" ? 10 : 7;

On 20 October 2017 at 17:37, nop head <[hidden email]> wrote:
You can modify variables in OpenSCAD. The values defined in the branches of the if only last until the closing brace.

You need something like this:

min_aleat = opengrid == "S" ? 1 :
                  opengrid == "M" ? 10 : 7;


On 20 October 2017 at 16:47, ashuan <[hidden email]> wrote:
Hello,

I have a group of 3D objects.
Each of one have a different and random configuration.

For this, i use rands like that :
   random_vect=rands(1,40,(nbCriterias1*nbCriterias2));

everything went well until i try to use 3 configurations of rands like this
:
   random_vect=rands(1,40,(nbCriterias1*nbCriterias2));
   random_vect=rands(10,10,(nbCriterias1*nbCriterias2));
   random_vect=rands(7,12,(nbCriterias1*nbCriterias2));

I have do a switch with cumulated if like that :
    min_aleat = 1;
    max_aleat = 40;
    random_vect=[];
    if (opengrid == "S")
    { // case S: full random
        min_aleat = 1;
        max_aleat = 40;
    } else {
        if (opengrid == "M")
        {   // case M: no random
            min_aleat = 10;
            max_aleat = 10;
        } else { // case L: little random
            min_aleat = 7;
            max_aleat = 12;
        }
    }
     random_vect=rands(min_aleat,max_aleat,(nbCriterias1*nbCriterias2));

my ifs are ok, i've control there with echo instruction.

The pb are, each time, i have the same rands response.
It didn't look about my criterias even if i replace my variable by direct
number.

Do you understand where i have make a mistake ?



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Problem about rands use

ashuan
In reply to this post by nophead
Thanks, that perfecly work.
I don't understand why we could'nt change variable values but your solution
are worked.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org