discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Problem about rands use

A
ashuan
Fri, Oct 20, 2017 3:47 PM

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,(nbCriterias1nbCriterias2));
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/

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/
NH
nop head
Fri, Oct 20, 2017 4:37 PM

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 laurent.sass@gmail.com 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,(nbCriterias1nbCriterias2));
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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

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 <laurent.sass@gmail.com> 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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
NH
nop head
Fri, Oct 20, 2017 4:38 PM

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 nop.head@gmail.com 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 laurent.sass@gmail.com 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,(nbCriterias1nbCriterias2));
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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

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 <nop.head@gmail.com> 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 <laurent.sass@gmail.com> 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 >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> > >
A
ashuan
Mon, Oct 23, 2017 10:22 AM

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/

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/