How To Generate Pseudorandom Chunks Kinda Like Minecraft?

Okay, I’m struggling to make the title Explanatory.

Using the Graphing Calculator, I need to fill every grid square in the plane with n pseudo random points. Obviously, I need to limit the “render distance”, so I create a list of the grid squares that are on screen. To make sure each grid square keeps the same set of random points no matter where the viewport is centered, each grid square needs a unique seed (I just do seed = i + j * 2^26).

But Desmos’s lack of support for nested lists kills me. I need to generate a list of random points for each grid square in a list of grid squares.

I want to do random(n, seeds), but seeds is a list of seeds, and it doesn’t work. If I didn’t need the seeds, I could just do random(n * m), where m is the number of grid squares to cover, but I can’t.

Edits (links):

Here’s a link to where I was testing my options: https://www.desmos.com/calculator/3tmhlncqlj

And here was the intended application, where I’m still using a pacman style wraparound method to shuffle points around instead of generating new ones (the color scheme is intended for reverse contrast mode, fyi, which can be activated in the graph settings at the top right of the screen, the little wrench thing): https://www.desmos.com/calculator/28h4n2o4kc

1 Like

I’m not sure about how you’re going to use those random numbers …
but there are many possible solutions, for example you could define:
R(n, seeds, h) = random(n, seeds[h] )
this would represent the n random numbers associated with index h.
If h needs to span a grid than h = i + j * 26 (if the grid is 26*26).

But the solution depends on the use of the numbers in the graph.
You could also have just one seed and generate a long list of random numbers
that are used for all the squares …

2 Likes

Generating one long list for all the squares is of course ideal, and I mentioned the scenario, but I need existing squares to retain their points as originally generated even after leaving and coming back.

Specifically, imagine squares are represented by the coordinate of their bottom left corner, and the square in “frame” are (0,0) and (1,0). I generate n random points within each square, then move the frame so that now the squares (1,0) and (2,0) are in frame. Square (2,0) gets a new set of random points, square (1,0) keeps the points it has, and square (0,0) is dropped. However, when I move the frame back so that square (0,0) is in frame again, it needs to regain the same points that were originally generated for it.

This pattern needs to be extendable across essentially the entire xy plane, kind of like minecraft chunk generation, except you regenerate the chunks every time they come into “render distance”.

You R(n, seeds, h) idea might work, I’ll look into it.

I did separately run into an issue with the instability of Desmos’s random number generator. Each expression entry gets its own secret seed upon creation that influences the random number generator, so when I did my deconstructed list solution, I needed to make sure that every square stayed at a stable position in the list of squares, which I accomplished with modular arithmetic.

I also added a poisson distribution to the number of points per square for maximal randomness.

If you’re curious about the application, I was generating an infinitely traversable representation of the universe with randomly distributed “stars” or galaxies, or whatever you’d like the random points to be.

In the end, though, I’ve found it easier and cheaper resource-wise to make a pacman universe instead. Who’s going to notice if the random distribution repeats? So I’m not sure I really want to go forward with the infinite distribution. If I can optimize the process so it’s not so dang slow, I might figure it’s worth it to do the chunk generation.

Anyways, thanks for the quick and useful response!