Random Integer Code?
26 posts • Page 1 of 2 • 1, 2
Random Integer Code?
So i need a code that can give me a random integer. So i did some research and i found a code on Phunland Forums but sadly it didn't work. So do any of yall know how to spawn a random integer that is between two numbers and i whole not 5.634141....1341324 and so on?
-
niffirg1 - Posts: 376
- Joined: Mon Aug 31, 2009 10:31 pm
- Location: The Great American South!
Re: Random Integer Code?
spawn something without speciying color, then read that color for the number. then you canuse multiplications and such for giving that random number area you want.
Jrv wrote:TC42 wrote:Quite honestly, I didn't think anyone on 4chan has that good a use of grammar, spelling, usage, mechanics, ect.
But I've never been there, so I may be wrong.
GTFO newfgt
-
RA2lover - Posts: 607
- Joined: Mon Aug 31, 2009 8:43 pm
- Location: Brazil
Re: Random Integer Code?
What do you mean by canuse multiplications?
-
niffirg1 - Posts: 376
- Joined: Mon Aug 31, 2009 10:31 pm
- Location: The Great American South!
Re: Random Integer Code?
RA2lover wrote:spawn something without speciying color, then read that color for the number. then you can use multiplications and such for giving that random number area you want.
He means you could multiply the numbers together to make a random random number.
Or you could use this site.
-
Sonic - Posts: 1467
- Joined: Tue Sep 01, 2009 6:18 pm
- Location: America!!!
Re: Random Integer Code?
Do you need it for Algodoo or just for something in real life?
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: Random Integer Code?
the multiplication was just for determining range.
in normal spawning, it ranges between 0 and 1
so, the formula for giving that range would be
minimum range + [random number * (maxrange-minrange)]
in normal spawning, it ranges between 0 and 1
so, the formula for giving that range would be
minimum range + [random number * (maxrange-minrange)]
Jrv wrote:TC42 wrote:Quite honestly, I didn't think anyone on 4chan has that good a use of grammar, spelling, usage, mechanics, ect.
But I've never been there, so I may be wrong.
GTFO newfgt
-
RA2lover - Posts: 607
- Joined: Mon Aug 31, 2009 8:43 pm
- Location: Brazil
Re: Random Integer Code?
if you want an integer, use math.toint(scene.my.randnumberresult)
Jrv wrote:TC42 wrote:Quite honestly, I didn't think anyone on 4chan has that good a use of grammar, spelling, usage, mechanics, ect.
But I've never been there, so I may be wrong.
GTFO newfgt
-
RA2lover - Posts: 607
- Joined: Mon Aug 31, 2009 8:43 pm
- Location: Brazil
Re: Random Integer Code?
Ahh, but is it truely random? Remember, no human generated number is truely random.
-
Sonic - Posts: 1467
- Joined: Tue Sep 01, 2009 6:18 pm
- Location: America!!!
Re: Random Integer Code?
and no nature-generated number is truly random. butterfly effect FTW!
Jrv wrote:TC42 wrote:Quite honestly, I didn't think anyone on 4chan has that good a use of grammar, spelling, usage, mechanics, ect.
But I've never been there, so I may be wrong.
GTFO newfgt
-
RA2lover - Posts: 607
- Joined: Mon Aug 31, 2009 8:43 pm
- Location: Brazil
Re: Random Integer Code?
To get a truly random number, you have to do something with isotopes. I don't remember exactly what.
-
Sonic - Posts: 1467
- Joined: Tue Sep 01, 2009 6:18 pm
- Location: America!!!
Re: Random Integer Code?
I once made a random function for algodoo.
It produces random float numbers from min to max. Like RA2lover already said, use math.toInt( scene.my.random(min, max) ) to make random integer values.
btw. it's no real randomness. No computer algorithm can produce real random numbers. But it's very good so even if you playback the exact same scene with scene.my.random in parallel you can't see any equalities between the "random" numbers.
It produces random float numbers from min to max. Like RA2lover already said, use math.toInt( scene.my.random(min, max) ) to make random integer values.
- Code: Select all
scene.my.memory = 17;
scene.my.random = (min, max)=>
{
x := scene.my.memory;
m := 1249 * 373;
x = x ^ 2 % m;
x == 0 ? {scene.my.memory = x + 1} : {scene.my.memory = x};
x * (max - min) / (1249 * 373.0) + min
}
btw. it's no real randomness. No computer algorithm can produce real random numbers. But it's very good so even if you playback the exact same scene with scene.my.random in parallel you can't see any equalities between the "random" numbers.
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: Random Integer Code?
There's quantum randomness. Some quantum-based processes, like radioactive decay are truely random. Decay counting detectors are used in cryptography to get really random numbers.
Phundamentalist
-
davidz40 - Posts: 438
- Joined: Sun Sep 06, 2009 10:30 am
Re: Random Integer Code?
I actually saw a book of a millon random numbers. Some people have too much time on their hands.
-
Sonic - Posts: 1467
- Joined: Tue Sep 01, 2009 6:18 pm
- Location: America!!!
Re: Random Integer Code?
no numbers are random. if quantum decay would be random, then THROW AWAY THE ATOMIC CLOCKS!!!!1111eleven!one!!!!11
Jrv wrote:TC42 wrote:Quite honestly, I didn't think anyone on 4chan has that good a use of grammar, spelling, usage, mechanics, ect.
But I've never been there, so I may be wrong.
GTFO newfgt
-
RA2lover - Posts: 607
- Joined: Mon Aug 31, 2009 8:43 pm
- Location: Brazil
Re: Random Integer Code?
RA2lover wrote:no numbers are random. if quantum decay would be random, then THROW AWAY THE ATOMIC CLOCKS!!!!1111eleven!one!!!!11
atomic clocks don't work with nuclear disintegration. time is derived with the frequency of photons that are emitted when isotops (mainly of cesium) change their energy state(?) (i don't know the exact english word for this)
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: Random Integer Code?
I'm no nuclear physiscist, but I but I beleive you mean when they "decay."
-
Sonic - Posts: 1467
- Joined: Tue Sep 01, 2009 6:18 pm
- Location: America!!!
Re: Random Integer Code?
yeah i don't know the correct english word so maybe "nuclear disintegration" is wrong but with "energy state" i don't mean "decay". i mean when electrons in an atom spontaneously give away energy
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: Random Integer Code?
Can someone tell me if Math.toInt is supposed to work in Phun?
And if not, what's the sinplest solution?
And if not, what's the sinplest solution?
- Antotabo
- Posts: 54
- Joined: Tue Sep 01, 2009 6:27 am
Re: Random Integer Code?
Nope it doesn't work in phun.
Or you can be creative and invent a better one.
- Code: Select all
scene.my.round = (x) => {(math.mod (x,1) < .5) ? (x - math.mod (x,1)) : (x - math.mod (x,1) + 1)}
scene.my.int10 = (x) => {X==0 ? 0 : X==1 ? 1 : X==2 ? 2 : X==3 ? 3 : X==4 ? 4 : X==5 ? 5 : X==6 ? 6 : X==7 ? 7 : X==8 ? 8 : X==9 ? 9 : 9}
Scene.my.float2int := (f)=>{f < 9.5 ? scene.my.int10(scene.my.round(f)) : {scene.my.float2int(f / 10) * 10 + scene.my.int10(math.mod(scene.my.round(f), 10))}}
infix 1 right: #_ => scene.my.float2int;
//now try:
12.444 / 5
// gives 2.4888
#12.444 / 5
// gives 2
Or you can be creative and invent a better one.
-
Mystery - Posts: 2802
- Joined: Thu Sep 03, 2009 1:16 pm
- Location: Southern Australia
Re: Random Integer Code?
randomness has nothing to do with the actual possibility of prediction but rather if the observer can predict it so while you could predict a roll of dice with a bunch of cameras, sensors and a supercomputer if you dont then the roll of dice is for all intents and purposes - random. if you wanna be extra sure that no human can predict(yet) the outcome you basically have to hook a geiger counter to a barrel of plutonium, done!
for algodoo however random=(scene.addcircle()).color(0)
for algodoo however random=(scene.addcircle()).color(0)
- Mr_Stabby
- Posts: 155
- Joined: Wed Dec 16, 2009 12:16 am
Re: Random Integer Code?
Now this is one random Thread reopening........
-
niffirg1 - Posts: 376
- Joined: Mon Aug 31, 2009 10:31 pm
- Location: The Great American South!
Re: Random Integer Code?
Mr_Stabby wrote:randomness has nothing to do with the actual possibility of prediction but rather if the observer can predict it so while you could predict a roll of dice with a bunch of cameras, sensors and a supercomputer if you dont then the roll of dice is for all intents and purposes - random. if you wanna be extra sure that no human can predict(yet) the outcome you basically have to hook a geiger counter to a barrel of plutonium, done!
for algodoo however random=(scene.addcircle()).color(0)
Your code isn't working good, a-a-a... it isn't working at all.
working code
- Code: Select all
random=(scene.addcircle({density:=0})).color(0)
-
Nait - Posts: 224
- Joined: Fri Oct 30, 2009 1:56 am
- Location: Eastern Russia, Vladivostok
Re: Random Integer Code?
Last edited by Nait on Sun Apr 25, 2010 11:10 am, edited 1 time in total.
-
Nait - Posts: 224
- Joined: Fri Oct 30, 2009 1:56 am
- Location: Eastern Russia, Vladivostok
Re: Random Integer Code?
Nait wrote:Here it is
[scene]40744[/scene]
Nope i don't see it.
-
Mystery - Posts: 2802
- Joined: Thu Sep 03, 2009 1:16 pm
- Location: Southern Australia
Re: Random Integer Code?
If you clone a circle 100 times upon itself what's deciding whether wich way each circle should go??(always wondered that )
make sure to check out my work.
-
Rideg - Posts: 948
- Joined: Tue Dec 15, 2009 5:17 pm
- Location: Östersund, Sweden
26 posts • Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 8 guests