[Sidefx-houdini-list] randomize P[y]

Neil Dickson ndickson at sidefx.com
Mon Jan 23 11:49:26 EST 2017


Good question!

It's because vector4 uses single-precision floating-point numbers, which
have only 24 bits of precision, but integers like @ptnum have 32-bits (more
like 31, but close enough).  If I just put @ptnum into the first component,
the results would start repeating after 16,777,216 points (i.e. 2^24).  The
results for points (2^24)+2k+1 would all be the same as (2^24)+2k, so
repeating pairs until 33,554,432, when it'll be sets of 4 that are all the
same, then at 67,108,864, it'll be sets of 8 that are all the same, etc.
@ptnum/65536 is the high 16 bits of @ptnum, and @ptnum%65536 is the low 16
bits of @ptnum, so both of them can be represented exactly as a
single-precision floating-point number, and all of the bits in @ptnum are
represented.  If @ptnum ever becomes 64-bit in VEX, it'll be able to handle
about 1.1 trillion points (i.e. 2^(16+24)) before issues crop up.

People often run into issues with random seeds when they get beyond
16,777,216 points when they don't take this into account, so it's good to
keep in mind.  The other big issue that people hit is accidentally reusing
seeds, which is why the default "Global Seed" on Attribute Randomize is
chosen based on the node ID when the node is placed, to reduce the chance
of people accidentally reusing seeds.  However, that also means that if you
put down two Attribute Randomize nodes, they'll produce different results
until you change their seeds to be the same, so there's no perfect solution.

Cheers,
Neil

On Sat, Jan 21, 2017 at 8:36 AM, Andy Nicholas <andy at andynicholas.com>
wrote:

> Hi Neil,
> Would you be able to explain the reason you’re using 2^16 in particular as
> the modulo and divisor for your seed? I understand the motivation, just not
> why that particular value :)
>
> Thanks!
> Andy
>
>
> > On 20 Jan 2017, at 23:46, Neil Dickson <ndickson at sidefx.com> wrote:
> >
> > Yep, I completely agree that it'd be convenient to write to a single
> > component, even though the workaround is fairly simple.
> >
> > I'm guessing you mean you want a "Uniform (Continuous)" distribution?  If
> > that's the case, it's pretty easy to do something entirely in Attribute
> > Wrangle, though Attribute Randomize does handle hashing the seed(s)
> nicely,
> > but it should be roughly equivalent to:
> >
> > vector4 vseed = set(@ptnum%65536, at ptnum/65536,0,chf("seed"));
> > float u = random(random_fhash(vseed));
> > @P.y = fit01(u, chf("min"), chf("max"));
> >
> > It's a bit overkill for most cases, but I wanted to make sure seeds were
> > handled well in Attribute Randomize, because it can sometimes cause
> strange
> > problems if they're not.  You can put that code in an Attribute Wrangle,
> > hit the "Create spare parameters..." button next to the code, and adjust
> > the seed, min, and max values.
> >
> > Cheers,
> > Neil
> >
> >
> > On Fri, Jan 20, 2017 at 5:41 PM, Gregory Ecker <gregory.ecker at gmail.com>
> > wrote:
> >
> >> maybe just randomize an attribute 'like offsetY' and add that to your P
> in
> >> a wrangle after the randomize.
> >>
> >> -G
> >>
> >> On Fri, Jan 20, 2017 at 5:37 PM, Gary Jaeger <gary at corestudio.com>
> wrote:
> >>
> >>> Thanks Neil. Just to be able to do a random distribution of P[y] so
> that
> >>> my little boxes are randomly placed on the y axis. For instance, if you
> >> put
> >>> an attribrandomize beneath the scatter, set it to P, set Dimensions to
> >> 1and
> >>> mess with the scale, you can scaled random placement on the X. I assume
> >>> because X is the first of [x,y,z]. But what if you want the same for Y?
> >> Or
> >>> Z for that matter. i.e. don’t touch X or Z, but randomize Y.
> >>>
> >>> Gary Jaeger / 650.728.7957 direct / 415.518.1419 mobile
> >>> http://corestudio.com <http://corestudio.com/>
> >>>> On Jan 20, 2017, at 10:30 AM, Neil Dickson <ndickson at sidefx.com>
> >> wrote:
> >>>>
> >>>> "While P works in the Attribute Name (and randomizes all three
> values),
> >>>> P[y] doesn’t. Why is that?"
> >>>>
> >>>> Sorry for the silly answer, but it's because "P[y]" isn't an attribute
> >>>> name.  I agree that it's a bummer that it doesn't yet have a special
> >> case
> >>>> to write to just *part* of an attribute, something like "P.y" or
> "P[1]"
> >>>> meaning the second component of P.  Please feel free to submit an RFE.
> >>> You
> >>>> can also write to an attribute named y, and then do @P.y = @y; in an
> >>>> Attribute Wrangle afterward.
> >>>>
> >>>> It's also just VEX inside, and most of the distributions are just
> >>>> delegating to VEX functions for sampling the distribution, so you can
> >> put
> >>>> together a custom thing fairly easily.  What distribution did you want
> >> to
> >>>> sample for the P.y values?
> >>>>
> >>>> Cheers,
> >>>> Neil
> >>>>
> >>>> On Fri, Jan 20, 2017 at 1:02 PM, Gary Jaeger <gary at corestudio.com>
> >>> wrote:
> >>>>
> >>>>> I was playing around with a basic setup using boxes copied to a
> >> scatter,
> >>>>> then using attribrandomize nodes below the scatter to muck things up.
> >> I
> >>>>> decided I’d try to just randomize only the y position. While P works
> >> in
> >>> the
> >>>>> Attribute Name (and randomizes all three values), P[y] doesn’t. Why
> is
> >>>>> that?  I’ve tried different combinations of Dimensions etc but now
> >> I’ve
> >>>>> given up.
> >>>>>
> >>>>> Gary Jaeger / 650.728.7957 direct / 415.518.1419 mobile
> >>>>> http://corestudio.com <http://corestudio.com/>
> >>>>> _______________________________________________
> >>>>> Sidefx-houdini-list mailing list
> >>>>> Sidefx-houdini-list at sidefx.com
> >>>>> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
> >>>>>
> >>>> _______________________________________________
> >>>> Sidefx-houdini-list mailing list
> >>>> Sidefx-houdini-list at sidefx.com
> >>>> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
> >>>
> >>> _______________________________________________
> >>> Sidefx-houdini-list mailing list
> >>> Sidefx-houdini-list at sidefx.com
> >>> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
> >>>
> >> _______________________________________________
> >> Sidefx-houdini-list mailing list
> >> Sidefx-houdini-list at sidefx.com
> >> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
> >>
> > _______________________________________________
> > Sidefx-houdini-list mailing list
> > Sidefx-houdini-list at sidefx.com
> > https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
>
> _______________________________________________
> Sidefx-houdini-list mailing list
> Sidefx-houdini-list at sidefx.com
> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
>



More information about the Sidefx-houdini-list mailing list