Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Getting a unique random number from within a table?

Is there any method of creating a unique random number every time it is called from in a table? I'm currently using:

["Main"]=	CFrame.new(1.26865196, -0.568903923, -2.47046661, 0.995743334, 0.0894539207, -0.022211533, -0.0921702608, 0.96639806, -0.239957407, 5.04754247e-008, 0.240983203, 0.970529377),

as a means of animating a part, however trying to use something like:

["Main"]=	CFrame.new(math.random(1.24865196 , 1.28865196), -0.568903923, -2.47046661, 0.995743334, 0.0894539207, -0.022211533, -0.0921702608, 0.96639806, -0.239957407, 5.04754247e-008, 0.240983203, 0.970529377),

leaves me with only 1 random number, which is countinually called. Is there any way I can ensure that this is a random number?

1 comment

0

Use a function or explain yourself better dude

1 answer

Enter, functions

Whilst you're out of luck if you want to do this so that every time you access yourTable.Main it has the CFrame with a different random number, you can instead have Main be a function which returns the new generated CFrame.


math.random doesn't play nice with fractions

Yes, I know, annoying. You can probably use a lerp for this, however.

CFrame.new(1.24865196 + (1.28865196-1.24865196)*math.random(), -0.568903923, -2.47046661, 0.995743334, 0.0894539207, -0.022211533, -0.0921702608, 0.96639806, -0.239957407, 5.04754247e-008, 0.240983203, 0.970529377),

What that will do is choose a random number between 1.28865196 and 1.24865196 by using the fact that math.random already makes a fraction between 0 and 1, and applying it to a simple lerp.

2 comments

0

Still can't get it to work. Appreciate the help though!

0

Did you use a function like I said?

This discussion is preserved as it was. New answers, comments, and votes are closed.