math.random
19 posts • Page 1 of 1
math.random
I know this might have been suggested before, but I looked up "math.random" and "random number" and other various crap and got nothing.
There should be a math.random function in the script. So if I wanted a number between 1 and ten, I'd type:
(I must thank TC42 for this... He was the one who first came up with the math.random(min, max).)
There should be a math.random function in the script. So if I wanted a number between 1 and ten, I'd type:
- Code: Select all
math.random(1, 10)
(I must thank TC42 for this... He was the one who first came up with the math.random(min, max).)
Phundementalism?
Ain't nobody got thyme fo dat.
Ain't nobody got thyme fo dat.
-

mold999 - Posts: 225
- Joined: Sun Jan 02, 2011 1:35 am
- Location: [176436, 3763234]
Re: math.random
Nope, actually that was Kilinich or Grady, I think.
-

TC42 - Posts: 984
- Joined: Sun Jan 09, 2011 1:53 pm
- Location: $ sudo apt get-install sandwich_
Re: math.random
I support. We've needed this for a while now.
-

Sonic - Posts: 1467
- Joined: Tue Sep 01, 2009 6:18 pm
- Location: America!!!
Re: math.random
Hmm... Last time I remember math.random being suggested, I suggested it. That was, however, yesterday. And on a scene.my.random topic of TC42's.
I would also suggest a math.randGauss function- it would pick a number with Gaussian distribution.
The graph of a Gaussian function is better known to some as a bell curve.
I still support anyway.
I would also suggest a math.randGauss function- it would pick a number with Gaussian distribution.
The graph of a Gaussian function is better known to some as a bell curve.
I still support anyway.
Matthias Wandel is epic, in my humble opinion.
I love my brain...
ARE YA HAPPY NOW?????
Thymechanic/Phundamentalist
Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.
ARE YA HAPPY NOW?????
Thymechanic/Phundamentalist
Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
-

Someone Else - Posts: 1147
- Joined: Sun Nov 21, 2010 10:53 pm
- Location: The Milky Way Galaxy
Re: math.random
How would a Gaussian division help it?
-

Sonic - Posts: 1467
- Joined: Tue Sep 01, 2009 6:18 pm
- Location: America!!!
Re: math.random
Sonic wrote:How would a Gaussian division help it?
Who cares?
Somebody'd use it, right?
Matthias Wandel is epic, in my humble opinion.
I love my brain...
ARE YA HAPPY NOW?????
Thymechanic/Phundamentalist
Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.
ARE YA HAPPY NOW?????
Thymechanic/Phundamentalist
Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
-

Someone Else - Posts: 1147
- Joined: Sun Nov 21, 2010 10:53 pm
- Location: The Milky Way Galaxy
Re: math.random
Support. But I don't think 2 arguments are best for random. 
NOTE: I'm not an Algoryx member.
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
-

tatt61880 - [Most Helpful Person 2010]
- Posts: 1150
- Joined: Mon Aug 31, 2009 5:45 pm
- Location: Tokyo, Japan
Re: math.random
tatt61880 wrote:Support. But I don't think 2 arguments are best for random.
So long as there aren't any arguments against it, I think it should be seriously considered.
Phundementalism?
Ain't nobody got thyme fo dat.
Ain't nobody got thyme fo dat.
-

mold999 - Posts: 225
- Joined: Sun Jan 02, 2011 1:35 am
- Location: [176436, 3763234]
Re: math.random
I would disagree, Tatt. Two arguments (one for minimum value, the other for maximum value) would work perfectly.
TheWinkits wrote:They both looks of cuking amazing
-

Chronos - [Most Active Member 2010]
- Posts: 4457
- Joined: Mon Aug 31, 2009 6:00 pm
- Location: Californania
Re: math.random
TC42 wrote:Nope, actually that was Kilinich or Grady, I think.
it was me if i remember correctly (the first one without just using periodic trigonometric functions or the color values of spawning objects). it has of course two parameters: "min" and "max"
it was always here for 1.5 years.
but kilinich made a neat and short function half a year ago which is way cooler in my opinion.
it's right here
i was inactive for over a year so please tell me if i missed anything important. but i've already noticed that there are a lot of actual scripting problems which were already solved over 1 or 2 years ago.
having said this: use the search bar peepz

-

KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: math.random
welcome back, i suppose...
i kinda have a suggestion for this:
just a suggestion....
i kinda have a suggestion for this:
- Code: Select all
math.random( min, max, range)
range would let you select weather you want a whole number
e.g. 1
or if you want a decimal
e.g. 0.001 (would give you a number upto an accuracy of (0.001 e.g. 0.009 or 2.211)
so,
math.random(1, 2, 0.05),
could give a number such as, 1.55
just a suggestion....
When asking for help, READ THE STICKIES!
- electronicboy
- Posts: 1694
- Joined: Mon Aug 31, 2009 6:18 pm
Re: math.random
Well, I TOTTALY SUPPORT THIS ! I was going to make a scene needed this and this would be useful for many other things and if I am not wrong it should enable us to make genetic algorithms more easily. 
Gears are my favorite mechanism. Why do you think I have this username ? 
Make sure to spend some time to see my work http://www.algodoo.com/algobox/profile.php?id=96, just to kill sometime
PS: Gear97™ Is a trademark from me. Any unauthorized use of the term "Gear" for usernames or other naming ideas will be punished.
Make sure to spend some time to see my work http://www.algodoo.com/algobox/profile.php?id=96, just to kill sometime
PS: Gear97™ Is a trademark from me. Any unauthorized use of the term "Gear" for usernames or other naming ideas will be punished.
-

Gear97 - Posts: 146
- Joined: Sat Jan 02, 2010 5:34 pm
- Location: Brazil
Re: math.random
Yes, I actually have my own version... And I fully support full integration.
Here's my version:
I must now say that I really like the idea of having three arguments- minimum value, maximum value, and the step.
Note that the "step" argument doesn't quite work properly. It will spit out a number that is a multiple of the step, not a multiple of step, then added to min...
Note that math.mod with 0 as the second argument will spit out NaN. Hence the IF.
Relevance Factor of 0.1: We really do have elseIf structures at our disposal!
{false} ? {1} : {false} ? {2} : {true} ? {3} : {4} = 3
TC42, I'm amazed at how you pulled the correct syntax out of thin air!
Back on topic:
Doesn't work too well, but at least it does work. It will produce a value as described above, but not very precicely. Also, if you set it up to produce one of three values (i.e. scene.my.random2(0, 1, 0.5)), it will almost always produce the middle value.
Here's my version:
- Code: Select all
scene.my.random1 = (min, max, step)=>{
N = (((scene.addCircle({
collideSet := 0;
airFrictionMult = -inf;
pos := [+inf, +inf]
})).color(0)) * (max - min)) + min;
{step != 0} ? {N - math.mod(N, step)} : {N}
}
I must now say that I really like the idea of having three arguments- minimum value, maximum value, and the step.
Note that the "step" argument doesn't quite work properly. It will spit out a number that is a multiple of the step, not a multiple of step, then added to min...
Note that math.mod with 0 as the second argument will spit out NaN. Hence the IF.
Relevance Factor of 0.1: We really do have elseIf structures at our disposal!
{false} ? {1} : {false} ? {2} : {true} ? {3} : {4} = 3
TC42, I'm amazed at how you pulled the correct syntax out of thin air!
Back on topic:
- Code: Select all
scene.my.random2 = (min, max, step)=>{
N = ((scene.addCircle({
collideSet := 0;
airFrictionMult = -inf;
pos := [+inf, +inf]
})).color(0)) * (max - min);
{step != 0} ? {N - math.mod(N + (step * 0.1), step)} : {N} + min
}
Doesn't work too well, but at least it does work. It will produce a value as described above, but not very precicely. Also, if you set it up to produce one of three values (i.e. scene.my.random2(0, 1, 0.5)), it will almost always produce the middle value.
Matthias Wandel is epic, in my humble opinion.
I love my brain...
ARE YA HAPPY NOW?????
Thymechanic/Phundamentalist
Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.
ARE YA HAPPY NOW?????
Thymechanic/Phundamentalist
Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
-

Someone Else - Posts: 1147
- Joined: Sun Nov 21, 2010 10:53 pm
- Location: The Milky Way Galaxy
Re: math.random
Support! Might come in handy 
The Simulation of Everything
I dream of a massive collab to make an accurate simulator of the evolution of space (id=56341), evolution of beings (id=56522), and chemicals (id=43179), etc. all wrapped into one.
I dream of a massive collab to make an accurate simulator of the evolution of space (id=56341), evolution of beings (id=56522), and chemicals (id=43179), etc. all wrapped into one.
-

Mag8328 - Posts: 16
- Joined: Wed Jun 22, 2011 12:40 am
Re: math.random
Total Support 
Heres My Sig
:
UNDER CONSTRUCTION
UNDER CONSTRUCTION
UNDER CONSTRUCTION
UNDER CONSTRUCTION
UNDER CONSTRUCTION.......
UNDER CONSTRUCTION
-

willy101 - Posts: 6
- Joined: Sat Aug 06, 2011 5:02 pm
- Location: Somewhere..DUH!!
Re: math.random
Support, coz i fu***ng need this! 
no, rly
no, rly
I'm back! (not really!)
I'm also making real hardware, sometimes.
I'm also making real hardware, sometimes.
-

Kutis 96 - Posts: 107
- Joined: Mon Jun 28, 2010 7:49 pm
- Location: Chasing red dots.
19 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 11 guests






