round(rands)

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

round(rands)

eagleapex
I can't round a random number.

        num1 = rands(2,10,1,6747);
        num2 = 9.58674394;
        num3 = round(num1);
        num4 = round(num2);
    echo(num1);
    echo(num2);
    echo(num3);
    echo(num4);

this provides:
ECHO: [2.422436106950045]
ECHO: 9.58674394
ECHO: undef
ECHO: 10

I don't see anything wrong with trying to get a random integer with
this method. Is this a bug?


Chris Thompson, eagleapex.com
GPG key available
"Obscurity is a far greater threat to authors and creative artists
than piracy" -Tim O'Reilly

Reply | Threaded
Open this post in threaded view
|

Re: round(rands)

Giles Bathgate-2
Chris

rands returns a vector (list) of random numbers even though you are
telling it to return one random number in the list.

you need to do:

list=rands(2,10,1,6747);

num1=list[0];

etc...

Regards

Giles

On 16 July 2012 21:12, Chris Thompson <[hidden email]> wrote:

> I can't round a random number.
>
>         num1 = rands(2,10,1,6747);
>         num2 = 9.58674394;
>         num3 = round(num1);
>         num4 = round(num2);
>     echo(num1);
>     echo(num2);
>     echo(num3);
>     echo(num4);
>
> this provides:
> ECHO: [2.422436106950045]
> ECHO: 9.58674394
> ECHO: undef
> ECHO: 10
>
> I don't see anything wrong with trying to get a random integer with
> this method. Is this a bug?
>
>
> Chris Thompson, eagleapex.com
> GPG key available
> "Obscurity is a far greater threat to authors and creative artists
> than piracy" -Tim O'Reilly
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
> http://openscad.org - https://flattr.com/thing/121566

Reply | Threaded
Open this post in threaded view
|

Re: round(rands)

eagleapex
OK, like an Array?
        num1 = rands(2,10,1,6747);
        num7 = round(num1[0]);
    echo(num1[0]);
    echo(num7);
provides:
ECHO: 2.422436106950045
ECHO: 2

I added a bit of explanation to the User Manual.

Thanks!

Chris Thompson, eagleapex.com
GPG key available
"Obscurity is a far greater threat to authors and creative artists
than piracy" -Tim O'Reilly


On Mon, Jul 16, 2012 at 4:17 PM, Giles Bathgate
<[hidden email]> wrote:

> Chris
>
> rands returns a vector (list) of random numbers even though you are
> telling it to return one random number in the list.
>
> you need to do:
>
> list=rands(2,10,1,6747);
>
> num1=list[0];
>
> etc...
>
> Regards
>
> Giles
>
> On 16 July 2012 21:12, Chris Thompson <[hidden email]> wrote:
>> I can't round a random number.
>>
>>         num1 = rands(2,10,1,6747);
>>         num2 = 9.58674394;
>>         num3 = round(num1);
>>         num4 = round(num2);
>>     echo(num1);
>>     echo(num2);
>>     echo(num3);
>>     echo(num4);
>>
>> this provides:
>> ECHO: [2.422436106950045]
>> ECHO: 9.58674394
>> ECHO: undef
>> ECHO: 10
>>
>> I don't see anything wrong with trying to get a random integer with
>> this method. Is this a bug?
>>
>>
>> Chris Thompson, eagleapex.com
>> GPG key available
>> "Obscurity is a far greater threat to authors and creative artists
>> than piracy" -Tim O'Reilly
>> _______________________________________________
>> OpenSCAD mailing list
>> [hidden email]
>> http://rocklinux.net/mailman/listinfo/openscad
>> http://openscad.org - https://flattr.com/thing/121566
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
> http://openscad.org - https://flattr.com/thing/121566

Reply | Threaded
Open this post in threaded view
|

Re: round(rands)

Giles Bathgate-2
Chris

Good, except your terminology is a bit misleading a vector is
synonymous to an array or a list. A vector is not a single number.

Regards

Giles

On 16 July 2012 21:30, Chris Thompson <[hidden email]> wrote:

> OK, like an Array?
>         num1 = rands(2,10,1,6747);
>         num7 = round(num1[0]);
>     echo(num1[0]);
>     echo(num7);
> provides:
> ECHO: 2.422436106950045
> ECHO: 2
>
> I added a bit of explanation to the User Manual.
>
> Thanks!
>
> Chris Thompson, eagleapex.com
> GPG key available
> "Obscurity is a far greater threat to authors and creative artists
> than piracy" -Tim O'Reilly
>
>
> On Mon, Jul 16, 2012 at 4:17 PM, Giles Bathgate
> <[hidden email]> wrote:
>> Chris
>>
>> rands returns a vector (list) of random numbers even though you are
>> telling it to return one random number in the list.
>>
>> you need to do:
>>
>> list=rands(2,10,1,6747);
>>
>> num1=list[0];
>>
>> etc...
>>
>> Regards
>>
>> Giles
>>
>> On 16 July 2012 21:12, Chris Thompson <[hidden email]> wrote:
>>> I can't round a random number.
>>>
>>>         num1 = rands(2,10,1,6747);
>>>         num2 = 9.58674394;
>>>         num3 = round(num1);
>>>         num4 = round(num2);
>>>     echo(num1);
>>>     echo(num2);
>>>     echo(num3);
>>>     echo(num4);
>>>
>>> this provides:
>>> ECHO: [2.422436106950045]
>>> ECHO: 9.58674394
>>> ECHO: undef
>>> ECHO: 10
>>>
>>> I don't see anything wrong with trying to get a random integer with
>>> this method. Is this a bug?
>>>
>>>
>>> Chris Thompson, eagleapex.com
>>> GPG key available
>>> "Obscurity is a far greater threat to authors and creative artists
>>> than piracy" -Tim O'Reilly
>>> _______________________________________________
>>> OpenSCAD mailing list
>>> [hidden email]
>>> http://rocklinux.net/mailman/listinfo/openscad
>>> http://openscad.org - https://flattr.com/thing/121566
>> _______________________________________________
>> OpenSCAD mailing list
>> [hidden email]
>> http://rocklinux.net/mailman/listinfo/openscad
>> http://openscad.org - https://flattr.com/thing/121566
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
> http://openscad.org - https://flattr.com/thing/121566

Reply | Threaded
Open this post in threaded view
|

Re: round(rands)

eagleapex
ok. But rands could create a vector with a single number in it, and it
still needs to be handled as a vector, right?

I also notice that rands() does't ever recalculate a different number.
It always acts like there is a seed declared.
I made a module with a random number of elements, but each time the
module is called with rands() inside, it is the same number.
Is there a way to get new random numbers?

Chris Thompson, eagleapex.com
GPG key available
"Obscurity is a far greater threat to authors and creative artists
than piracy" -Tim O'Reilly


On Mon, Jul 16, 2012 at 4:37 PM, Giles Bathgate
<[hidden email]> wrote:

> Chris
>
> Good, except your terminology is a bit misleading a vector is
> synonymous to an array or a list. A vector is not a single number.
>
> Regards
>
> Giles
>
> On 16 July 2012 21:30, Chris Thompson <[hidden email]> wrote:
>> OK, like an Array?
>>         num1 = rands(2,10,1,6747);
>>         num7 = round(num1[0]);
>>     echo(num1[0]);
>>     echo(num7);
>> provides:
>> ECHO: 2.422436106950045
>> ECHO: 2
>>
>> I added a bit of explanation to the User Manual.
>>
>> Thanks!
>>
>> Chris Thompson, eagleapex.com
>> GPG key available
>> "Obscurity is a far greater threat to authors and creative artists
>> than piracy" -Tim O'Reilly
>>
>>
>> On Mon, Jul 16, 2012 at 4:17 PM, Giles Bathgate
>> <[hidden email]> wrote:
>>> Chris
>>>
>>> rands returns a vector (list) of random numbers even though you are
>>> telling it to return one random number in the list.
>>>
>>> you need to do:
>>>
>>> list=rands(2,10,1,6747);
>>>
>>> num1=list[0];
>>>
>>> etc...
>>>
>>> Regards
>>>
>>> Giles
>>>
>>> On 16 July 2012 21:12, Chris Thompson <[hidden email]> wrote:
>>>> I can't round a random number.
>>>>
>>>>         num1 = rands(2,10,1,6747);
>>>>         num2 = 9.58674394;
>>>>         num3 = round(num1);
>>>>         num4 = round(num2);
>>>>     echo(num1);
>>>>     echo(num2);
>>>>     echo(num3);
>>>>     echo(num4);
>>>>
>>>> this provides:
>>>> ECHO: [2.422436106950045]
>>>> ECHO: 9.58674394
>>>> ECHO: undef
>>>> ECHO: 10
>>>>
>>>> I don't see anything wrong with trying to get a random integer with
>>>> this method. Is this a bug?
>>>>
>>>>
>>>> Chris Thompson, eagleapex.com
>>>> GPG key available
>>>> "Obscurity is a far greater threat to authors and creative artists
>>>> than piracy" -Tim O'Reilly
>>>> _______________________________________________
>>>> OpenSCAD mailing list
>>>> [hidden email]
>>>> http://rocklinux.net/mailman/listinfo/openscad
>>>> http://openscad.org - https://flattr.com/thing/121566
>>> _______________________________________________
>>> OpenSCAD mailing list
>>> [hidden email]
>>> http://rocklinux.net/mailman/listinfo/openscad
>>> http://openscad.org - https://flattr.com/thing/121566
>> _______________________________________________
>> OpenSCAD mailing list
>> [hidden email]
>> http://rocklinux.net/mailman/listinfo/openscad
>> http://openscad.org - https://flattr.com/thing/121566
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
> http://openscad.org - https://flattr.com/thing/121566

Reply | Threaded
Open this post in threaded view
|

Re: round(rands)

Giles Bathgate-2
Chris,

Rands works this way because of the declarative nature of openscad.
Openscad is not an imperative programming language so the order in
which you make calls is unimportant. This is also why modifying
variables in openscad is not allowed (except via the assign module)

if you want more random numbers the idea is that you would call rands
with a larger value for the value count parameter.

You could use rands to make some seeds and then rands again to make
some other sets:

seed_vector = rands(0,1000,4,1234);

rand_vector1 = rands(0.1,2.0,1,seed_vector[0]);
rand_vector2 = rands(0.1,2.0,1,seed_vector[1]);
rand_vector2 = rands(0.1,2.0,1,seed_vector[2]);


does that do what you want?

Regards

Giles

On 16 July 2012 21:48, Chris Thompson <[hidden email]> wrote:

> ok. But rands could create a vector with a single number in it, and it
> still needs to be handled as a vector, right?
>
> I also notice that rands() does't ever recalculate a different number.
> It always acts like there is a seed declared.
> I made a module with a random number of elements, but each time the
> module is called with rands() inside, it is the same number.
> Is there a way to get new random numbers?
>
> Chris Thompson, eagleapex.com
> GPG key available
> "Obscurity is a far greater threat to authors and creative artists
> than piracy" -Tim O'Reilly
>
>
> On Mon, Jul 16, 2012 at 4:37 PM, Giles Bathgate
> <[hidden email]> wrote:
>> Chris
>>
>> Good, except your terminology is a bit misleading a vector is
>> synonymous to an array or a list. A vector is not a single number.
>>
>> Regards
>>
>> Giles
>>
>> On 16 July 2012 21:30, Chris Thompson <[hidden email]> wrote:
>>> OK, like an Array?
>>>         num1 = rands(2,10,1,6747);
>>>         num7 = round(num1[0]);
>>>     echo(num1[0]);
>>>     echo(num7);
>>> provides:
>>> ECHO: 2.422436106950045
>>> ECHO: 2
>>>
>>> I added a bit of explanation to the User Manual.
>>>
>>> Thanks!
>>>
>>> Chris Thompson, eagleapex.com
>>> GPG key available
>>> "Obscurity is a far greater threat to authors and creative artists
>>> than piracy" -Tim O'Reilly
>>>
>>>
>>> On Mon, Jul 16, 2012 at 4:17 PM, Giles Bathgate
>>> <[hidden email]> wrote:
>>>> Chris
>>>>
>>>> rands returns a vector (list) of random numbers even though you are
>>>> telling it to return one random number in the list.
>>>>
>>>> you need to do:
>>>>
>>>> list=rands(2,10,1,6747);
>>>>
>>>> num1=list[0];
>>>>
>>>> etc...
>>>>
>>>> Regards
>>>>
>>>> Giles
>>>>
>>>> On 16 July 2012 21:12, Chris Thompson <[hidden email]> wrote:
>>>>> I can't round a random number.
>>>>>
>>>>>         num1 = rands(2,10,1,6747);
>>>>>         num2 = 9.58674394;
>>>>>         num3 = round(num1);
>>>>>         num4 = round(num2);
>>>>>     echo(num1);
>>>>>     echo(num2);
>>>>>     echo(num3);
>>>>>     echo(num4);
>>>>>
>>>>> this provides:
>>>>> ECHO: [2.422436106950045]
>>>>> ECHO: 9.58674394
>>>>> ECHO: undef
>>>>> ECHO: 10
>>>>>
>>>>> I don't see anything wrong with trying to get a random integer with
>>>>> this method. Is this a bug?
>>>>>
>>>>>
>>>>> Chris Thompson, eagleapex.com
>>>>> GPG key available
>>>>> "Obscurity is a far greater threat to authors and creative artists
>>>>> than piracy" -Tim O'Reilly
>>>>> _______________________________________________
>>>>> OpenSCAD mailing list
>>>>> [hidden email]
>>>>> http://rocklinux.net/mailman/listinfo/openscad
>>>>> http://openscad.org - https://flattr.com/thing/121566
>>>> _______________________________________________
>>>> OpenSCAD mailing list
>>>> [hidden email]
>>>> http://rocklinux.net/mailman/listinfo/openscad
>>>> http://openscad.org - https://flattr.com/thing/121566
>>> _______________________________________________
>>> OpenSCAD mailing list
>>> [hidden email]
>>> http://rocklinux.net/mailman/listinfo/openscad
>>> http://openscad.org - https://flattr.com/thing/121566
>> _______________________________________________
>> OpenSCAD mailing list
>> [hidden email]
>> http://rocklinux.net/mailman/listinfo/openscad
>> http://openscad.org - https://flattr.com/thing/121566
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
> http://openscad.org - https://flattr.com/thing/121566

Reply | Threaded
Open this post in threaded view
|

Re: round(rands)

eagleapex
That's closer. I was hoping to recompile and get new random numbers,
which would change the model in an unexpected way. I could repeat
until I get something I like.
I'm trying for something more organic. It may not be possible.

Chris Thompson, eagleapex.com
GPG key available
"Obscurity is a far greater threat to authors and creative artists
than piracy" -Tim O'Reilly


On Mon, Jul 16, 2012 at 4:57 PM, Giles Bathgate
<[hidden email]> wrote:

> Chris,
>
> Rands works this way because of the declarative nature of openscad.
> Openscad is not an imperative programming language so the order in
> which you make calls is unimportant. This is also why modifying
> variables in openscad is not allowed (except via the assign module)
>
> if you want more random numbers the idea is that you would call rands
> with a larger value for the value count parameter.
>
> You could use rands to make some seeds and then rands again to make
> some other sets:
>
> seed_vector = rands(0,1000,4,1234);
>
> rand_vector1 = rands(0.1,2.0,1,seed_vector[0]);
> rand_vector2 = rands(0.1,2.0,1,seed_vector[1]);
> rand_vector2 = rands(0.1,2.0,1,seed_vector[2]);
>
>
> does that do what you want?
>
> Regards
>
> Giles
>
> On 16 July 2012 21:48, Chris Thompson <[hidden email]> wrote:
>> ok. But rands could create a vector with a single number in it, and it
>> still needs to be handled as a vector, right?
>>
>> I also notice that rands() does't ever recalculate a different number.
>> It always acts like there is a seed declared.
>> I made a module with a random number of elements, but each time the
>> module is called with rands() inside, it is the same number.
>> Is there a way to get new random numbers?
>>
>> Chris Thompson, eagleapex.com
>> GPG key available
>> "Obscurity is a far greater threat to authors and creative artists
>> than piracy" -Tim O'Reilly
>>
>>
>> On Mon, Jul 16, 2012 at 4:37 PM, Giles Bathgate
>> <[hidden email]> wrote:
>>> Chris
>>>
>>> Good, except your terminology is a bit misleading a vector is
>>> synonymous to an array or a list. A vector is not a single number.
>>>
>>> Regards
>>>
>>> Giles
>>>
>>> On 16 July 2012 21:30, Chris Thompson <[hidden email]> wrote:
>>>> OK, like an Array?
>>>>         num1 = rands(2,10,1,6747);
>>>>         num7 = round(num1[0]);
>>>>     echo(num1[0]);
>>>>     echo(num7);
>>>> provides:
>>>> ECHO: 2.422436106950045
>>>> ECHO: 2
>>>>
>>>> I added a bit of explanation to the User Manual.
>>>>
>>>> Thanks!
>>>>
>>>> Chris Thompson, eagleapex.com
>>>> GPG key available
>>>> "Obscurity is a far greater threat to authors and creative artists
>>>> than piracy" -Tim O'Reilly
>>>>
>>>>
>>>> On Mon, Jul 16, 2012 at 4:17 PM, Giles Bathgate
>>>> <[hidden email]> wrote:
>>>>> Chris
>>>>>
>>>>> rands returns a vector (list) of random numbers even though you are
>>>>> telling it to return one random number in the list.
>>>>>
>>>>> you need to do:
>>>>>
>>>>> list=rands(2,10,1,6747);
>>>>>
>>>>> num1=list[0];
>>>>>
>>>>> etc...
>>>>>
>>>>> Regards
>>>>>
>>>>> Giles
>>>>>
>>>>> On 16 July 2012 21:12, Chris Thompson <[hidden email]> wrote:
>>>>>> I can't round a random number.
>>>>>>
>>>>>>         num1 = rands(2,10,1,6747);
>>>>>>         num2 = 9.58674394;
>>>>>>         num3 = round(num1);
>>>>>>         num4 = round(num2);
>>>>>>     echo(num1);
>>>>>>     echo(num2);
>>>>>>     echo(num3);
>>>>>>     echo(num4);
>>>>>>
>>>>>> this provides:
>>>>>> ECHO: [2.422436106950045]
>>>>>> ECHO: 9.58674394
>>>>>> ECHO: undef
>>>>>> ECHO: 10
>>>>>>
>>>>>> I don't see anything wrong with trying to get a random integer with
>>>>>> this method. Is this a bug?
>>>>>>
>>>>>>
>>>>>> Chris Thompson, eagleapex.com
>>>>>> GPG key available
>>>>>> "Obscurity is a far greater threat to authors and creative artists
>>>>>> than piracy" -Tim O'Reilly
>>>>>> _______________________________________________
>>>>>> OpenSCAD mailing list
>>>>>> [hidden email]
>>>>>> http://rocklinux.net/mailman/listinfo/openscad
>>>>>> http://openscad.org - https://flattr.com/thing/121566
>>>>> _______________________________________________
>>>>> OpenSCAD mailing list
>>>>> [hidden email]
>>>>> http://rocklinux.net/mailman/listinfo/openscad
>>>>> http://openscad.org - https://flattr.com/thing/121566
>>>> _______________________________________________
>>>> OpenSCAD mailing list
>>>> [hidden email]
>>>> http://rocklinux.net/mailman/listinfo/openscad
>>>> http://openscad.org - https://flattr.com/thing/121566
>>> _______________________________________________
>>> OpenSCAD mailing list
>>> [hidden email]
>>> http://rocklinux.net/mailman/listinfo/openscad
>>> http://openscad.org - https://flattr.com/thing/121566
>> _______________________________________________
>> OpenSCAD mailing list
>> [hidden email]
>> http://rocklinux.net/mailman/listinfo/openscad
>> http://openscad.org - https://flattr.com/thing/121566
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
> http://openscad.org - https://flattr.com/thing/121566

Reply | Threaded
Open this post in threaded view
|

Re: round(rands)

Giles Bathgate-2

Chris,

There are limitations with the declarative programming model. If you think about it though your design will be indeterminate, and that's not generally desired for replicating parts. Except in your case ;) anyway if you'd like to try out my imperitive programming language version of openscad Google RapCAD

Regards

Giles

Reply | Threaded
Open this post in threaded view
|

Re: round(rands)

Giles Bathgate-2

Chris,

Another hint: enable animation, and pass $t to rands function as seed and watch your model change shapes as you run the animation.

Regards
Giles