# Rand Function

9 messages
Open this post in threaded view
|

## Rand Function

 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
Open this post in threaded view
|

## Re: Rand Function

 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 > _______________________________________________ > 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/
Open this post in threaded view
|

## Re: Rand Function

 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
Open this post in threaded view
|

## Re: Rand Function

 Administrator In reply to this post by Giles Bathgate-2 Sorry again for the loong delay. This is now applied and committed.  -Marius
Open this post in threaded view
|

## Re: Rand Function

 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
Open this post in threaded view
|

## Re: Rand Function

 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
Open this post in threaded view
|

## Re: Rand Function

 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.. -MariusA 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