question

Mario García López avatar image
0 Likes"
Mario García López asked Mario García López commented

How to choose random output port

Depending on the case i'd like to choose a random port between 2 numbers. But it is not working, it always choose the same port.


/**Custom Code*/

Object item = param(1);

Object current = ownerobject(c);

/***popup:ValuesByCase:valuestr=Port*/

/**Port By Case*/


Variant value = /***tag:ValueFunc*//**/item.persona/**/;


/***tagex:data*/

if (value == /**/1/**/) {

return /**/1/**/;

}


if (value == /**/2/**/) {

return /**/1/**/;

}


if (value == /**/3/**/) {

return /**/duniform(2,4)/**/;

}


if (value == /**/4/**/) {

return /**/duniform(5,6)/**/;

}


if (value == /**/5/**/) {

return /**/7/**/;

}

/***/


return /***tag:default*//**/1/**/;


What is wrong?

FlexSim 24.2.0
randomportrandom number generator
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Felix Möhlmann avatar image Felix Möhlmann commented ·
The code is correct. Does the "persona" label actually exist on the item and are its values in the expected range? If not the code would default to sending all items through port 1.

It would be easier to help, if you could upload a model.

0 Likes 0 ·
Mario García López avatar image Mario García López commented ·
Yes it is, the rest of the cases works good. The problem is that when I reset and start de simulation, the cases with the random port go to the same port always
0 Likes 0 ·

1 Answer

Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered Mario García López commented

In an express license is randomness deactivated. Only licensed version uses randomness. You can tell then the system to deactivate randomness. Function is called repeat random streams in statistic menu.

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Mario García López avatar image Mario García López commented ·
Thank you so much, I can´t believe it was as simple as that
0 Likes 0 ·