A Random Feature

#6

Wow that local Name do stuff is blowing my mind I gotta test this real quick

And awesome can’t wait to use

3 Likes

#7

Well, that was random. Cool!

13 Likes

#8

can’t wait to be accurately random!
:thinking:

9 Likes

#9

Can the state be replicated between sessions, or saved with a place/model, or be read and set?

7 Likes

#10

You guys had better make me proud and make cool stuff with this!

9 Likes

#11

Random Simulator

Front page, let’s make it happen

8 Likes

#12

State doesn’t replicate/serialize/persist for now. That’s something we could totally look into if there turns out to be a strong-enough case for it.

For now, you can get similar results by saving the initial seed along with a count of how many times NextInteger+NextNumber have been called.

2 Likes

#13

Are you making any sense of the local Name do thing? Because I’m not. How the hell does it work lol.

1 Like

#14

local x = 0

do
local y = 3
x = 2 + y
end

print(x, y) -- 5, nil

He’s doing it like that so rng only exists in that do scope.

2 Likes

#15

What’s it good for? Memory optimisation?

1 Like

#16

Well, here’s a breakdown of how it works:

local Name – Stores the variable in the script

Now, a do statement is basically useless except for one thing: Scope.
The scope of a variable is where it can used - it has to be used within its scope.

When the scope is done, all variables assigned to it will be removed from the memory (I assume). The Name variable is out of the do's scope so it doesn’t get removed.

2 Likes

#17

That name oddly scared me for a moment.

EDIT: OH OH CLEVER TITLE

2 Likes

#18

It still exists in memory, since the function is using it. But it helps not pollute the global scope. So if you wanted to define multiple functions that use their own instances of Random this is one way to do it.

6 Likes

#19

I see, that’s good to know. Thanks! ( + @EmeraldSlash )

2 Likes

#20

This is a very awesome update. I can’t wait to test it out. :slight_smile:

1 Like

#21

Thank god for this. I’ll probably be using this for some sort of terrain generation.

0 Likes

#22

Heck yes! I wrote a deterministic RNG in Lua for Bloxel because I needed to generate infinite worlds based on world seeds. Now I can switch to this. Very thanking @Fractality_alt @0xBAADF00D

3 Likes

#23

Is math.random going to become depreciated now? Also if you just need a simple random number (like 1 or 2, and nothing more complicated than that) is there an advantage to either method? I would assume this new method is better.

0 Likes

#24

Heads up, we’ve temporarily disabled this feature until more platforms are on the latest version.
Stay tuned.

1 Like

#25

We’ve needed this for a long time. Thank you.

0 Likes