[OpenSCAD] MIssing Operators

Giles Bathgate giles.bathgate at gmail.com
Fri Sep 17 20:33:05 CEST 2010


The attached patch adds a rand() function to OpenSCAD

I expect that most people will use it like so:

module main()
{
  echo(rand(1,100));
  echo(rand(1,100));
  echo(rand(1,100));
}

main();

The output of this will be different each time you compile the script
but for example 

ECHO: 42.3678
ECHO: 16.6152
ECHO: 59.3326
 

The form is rand(min,max) where min is the minimum value and max is the
maximum value

However, some people might want a set of random numbers that are rooted
at a specific seed, in which case you can use the form
rand(min,max,seed) this would be used like this:

module main()
{
  echo(rand(1,100,2));
  echo(rand(1,100));
  echo(rand(1,100));
}

i.e. subsequent calls after a seed has been set should not pass a value
for seed.

The output of this will always be the same:
ECHO: 42.3678
ECHO: 16.6152
ECHO: 59.3326

(unless of course you use a different seed)

A further improvement might be to add a form rands(min,max,seed,amount)
which would return a Vector (array  or list) with 'amount' number of
elements

Regards

Giles  





-------------- next part --------------
A non-text attachment was scrubbed...
Name: rand.patch
Type: text/x-patch
Size: 1655 bytes
Desc: not available
Url : http://rocklinux.net/pipermail/openscad/attachments/20100917/b242b234/rand.bin


More information about the OpenSCAD mailing list