Rand Function

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

Rand Function

Giles Bathgate-2
After thinking about my previous solution a rands() function that
returns a Vector of random values is a much better approach because it
is stateless.

The two forms are

rands(min,max,num);

and

rands(min,max,num,seed);


So for example:

module main()
{
  v = rands(1,10,5,2);
  echo(v);
}

main();

outputs (always)

ECHO: [7.30879, 8.28709, 1.79916, 2.09331, 4.13476]

Regards

Giles

rand.patch.txt (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Rand Function

clothbot
I'd like to have both state and stateless options.  Saves the hassle of coming up with different seed values for every call when embedded in for loops and the like.

Andrew.


On 2010-09-17, at 3:24 PM, Giles Bathgate wrote:

> After thinking about my previous solution a rands() function that
> returns a Vector of random values is a much better approach because it
> is stateless.
>
> The two forms are
>
> rands(min,max,num);
>
> and
>
> rands(min,max,num,seed);
>
>
> So for example:
>
> module main()
> {
>  v = rands(1,10,5,2);
>  echo(v);
> }
>
> main();
>
> outputs (always)
>
> ECHO: [7.30879, 8.28709, 1.79916, 2.09331, 4.13476]
>
> Regards
>
> Giles
> <rand.patch.txt>_______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad

--

"The future is already here.  It's just not very evenly distributed" -- William Gibson

Me: http://clothbot.com/wiki/




Reply | Threaded
Open this post in threaded view
|

Re: Rand Function

Giles Bathgate-2
On Fri, 2010-09-17 at 15:48 -0400, Andrew Plumb wrote:
> I'd like to have both state and stateless options.  Saves the hassle of coming up with different seed values for every call when embedded in for loops and the like.
>
> Andrew.

In the first form you don't need a seed (it uses the system time as a
seed)

if you wanted random values in a for you would do this:

module main()

{

v=rands(1,10,5);

for(i=v)

{

echo(i);

}

}

main();


This is what made me think that the stateless thing was a good idea(TM)
as well as when you did this in the old scheme:

rand(1,10);
rand(1,10,2);
rand(1,10);

The behaviour was a bit odd

Regards

Giles


Reply | Threaded
Open this post in threaded view
|

Re: Rand Function

kintel
Administrator
In reply to this post by Giles Bathgate-2
Sorry again for the loong delay.
This is now applied and committed.

 -Marius


Reply | Threaded
Open this post in threaded view
|

Re: Rand Function

clothbot
Hey Marius,

When you get a chance, could you roll some new binaries for folks (myself included) to exercise new features like this rand() function?

Thanks!

Andrew.

On 2010-10-30, at 10:54 PM, Marius Kintel wrote:

Sorry again for the loong delay.
This is now applied and committed.

-Marius

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad

--

Makerbot Number Nine... #9... 0x09... 0o11... 0b1001... 
http://clothbot.com/wiki/MakerBotNumberNine



Reply | Threaded
Open this post in threaded view
|

Re: Rand Function

kintel
Administrator
On Jan 11, 2011, at 02:39 AM, Andrew Plumb wrote:

> When you get a chance, could you roll some new binaries for folks (myself included) to exercise new features like this rand() function?
>
Which platform?

I'm wanting to do a release of the current state, just to clean the slate, but I haven't gotten around to it yet..

 -Marius


Reply | Threaded
Open this post in threaded view
|

Re: Rand Function

clothbot

On 2011-01-10, at 9:32 PM, Marius Kintel wrote:

On Jan 11, 2011, at 02:39 AM, Andrew Plumb wrote:

When you get a chance, could you roll some new binaries for folks (myself included) to exercise new features like this rand() function?

Which platform?

I'm wanting to do a release of the current state, just to clean the slate, but I haven't gotten around to it yet..

-Marius

A Mac OS X openscad-latest.dmg snapshot is fine for me if you have one handy.

Thanks!

Andrew.

--

Makerbot Number Nine... #9... 0x09... 0o11... 0b1001... 
http://clothbot.com/wiki/MakerBotNumberNine



Reply | Threaded
Open this post in threaded view
|

Re: Rand Function

kintel
Administrator
On Jan 11, 2011, at 03:42 AM, Andrew Plumb wrote:
>
> A Mac OS X openscad-latest.dmg snapshot is fine for me if you have one handy.
>
I'm building one now. Will appear in the usual place..

 -Marius


Reply | Threaded
Open this post in threaded view
|

Re: Rand Function

clothbot
Hi Marius,

I just downloaded it and confirmed rands() works.  I've created a "rands" entry in the OpenSCAD docs.

Thanks!

Andrew.

On 2011-01-10, at 9:54 PM, Marius Kintel wrote:

On Jan 11, 2011, at 03:42 AM, Andrew Plumb wrote:

A Mac OS X openscad-latest.dmg snapshot is fine for me if you have one handy.

I'm building one now. Will appear in the usual place..

-Marius

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad

--

Makerbot Number Nine... #9... 0x09... 0o11... 0b1001... 
http://clothbot.com/wiki/MakerBotNumberNine