LCG Implementation in Nodes

My current objective is to create a noodle that acts as an LCG (linear congruential generator), using X and Y coordinates as inputs. For anyone familiar with LCG’s, the obvious problem is state, so an LCG setup might be impossible or too hackish. So for that reason, I’m not particularly hard up on using an LCG over other types. I set up a few nodes that took X and Y, and performed the basic equation seen just below. I haven’t really been able to make it work.

http://www.cs.princeton.edu/courses/archive/spr03/cs126/assignments/cycle.html

Long story short, I’d like a noodle that effectively generates a pseudo-random number. In my head, I imagine it taking X and Y as inputs, and if the noodle outputs some value greater than A, it outputs 1, otherwise 0 (or some weighted range between 0-1). The goal is being able to mix two materials in such a way that I get a pattern somewhere in the vicinity of this: https://s-media-cache-ak0.pinimg.com/564x/ae/d9/c3/aed9c3c40411f1fa0040b31d445ee0c8.jpg

If anyone can help out, I’d really appreciate it.

** To clarify, the random input from object data is not what I’m looking for. I’m looking for pseudo-random based on X and Y.

** One more clarification, I’m doing this in the game engine. So procedural texture inputs won’t work. Otherwise that’s exactly where I’d go.

Could you not use math->greater than with a noise or musgrave texture as the input, then use that to mix the shaders? that gives you this -


I know it’s not based on X and Y… but this is the way i would achieve the pattern you posted…

Ah. I’m sorry. One more clarification. Game Engine. Can’t use procedural texture inputs. Sorry about that. A good answer, none-the-less. If I wasn’t being difficult. :stuck_out_tongue:

There is LCG in cycles code … its to do with the sobol pattern used for rendering… maybe digging around here - https://wiki.blender.org/index.php/Dev:Source/Render/Cycles/Sobol could point you in the right direction… it mentions the use of LCG…

Not sure if the information could be extrapolated for use within the BGE, but you never know… it shows sections of code on there that might be usefull

Yeah. That’s coding though. I could write up a script, but I’m trying really hard to keep it all typical node… stuff. It might come down to scripting though. If it does, I’ll likely choose a better PRNG algorithm than LCG. For the moment, I’m thinking I’m going to default to a cloud noise texture made up in GIMP. Thanks anyway Jamie.

Okay :slight_smile: sorry i couldn’t help you out with a solution…

If i stumble upon any information on the subject, i will post the source for you on this thread :slight_smile:

For the Game engine, you may need to do some work in OpenGL. This will allow you to do your own procedural textures for the GE.