Random Integer Code?

About advanced scenes, and the Thyme scripting language used in Algodoo.

Random Integer Code?

Postby niffirg1 » Thu Dec 10, 2009 12:50 am

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?
User avatar
niffirg1
 
Posts: 376
Joined: Mon Aug 31, 2009 10:31 pm
Location: The Great American South!

Re: Random Integer Code?

Postby RA2lover » Thu Dec 10, 2009 1:44 am

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
User avatar
RA2lover
 
Posts: 607
Joined: Mon Aug 31, 2009 8:43 pm
Location: Brazil

Re: Random Integer Code?

Postby niffirg1 » Thu Dec 10, 2009 3:40 am

What do you mean by canuse multiplications?
User avatar
niffirg1
 
Posts: 376
Joined: Mon Aug 31, 2009 10:31 pm
Location: The Great American South!

Re: Random Integer Code?

Postby Sonic » Thu Dec 10, 2009 5:16 pm

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.
I do stuff and break things. You know how it is.
Image
User avatar
Sonic
 
Posts: 1467
Joined: Tue Sep 01, 2009 6:18 pm
Location: America!!!

Re: Random Integer Code?

Postby KarateBrot » Thu Dec 10, 2009 5:35 pm

Do you need it for Algodoo or just for something in real life?
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Random Integer Code?

Postby RA2lover » Thu Dec 10, 2009 5:51 pm

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)]
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
User avatar
RA2lover
 
Posts: 607
Joined: Mon Aug 31, 2009 8:43 pm
Location: Brazil

Re: Random Integer Code?

Postby RA2lover » Thu Dec 10, 2009 6:31 pm

Rating: rated 5.9
Filesize: 35.14 kB
Comments: 2
Ratings: 3
download


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
User avatar
RA2lover
 
Posts: 607
Joined: Mon Aug 31, 2009 8:43 pm
Location: Brazil

Re: Random Integer Code?

Postby Sonic » Thu Dec 10, 2009 6:39 pm

Ahh, but is it truely random? Remember, no human generated number is truely random.
I do stuff and break things. You know how it is.
Image
User avatar
Sonic
 
Posts: 1467
Joined: Tue Sep 01, 2009 6:18 pm
Location: America!!!

Re: Random Integer Code?

Postby RA2lover » Thu Dec 10, 2009 6:45 pm

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
User avatar
RA2lover
 
Posts: 607
Joined: Mon Aug 31, 2009 8:43 pm
Location: Brazil

Re: Random Integer Code?

Postby Sonic » Thu Dec 10, 2009 7:29 pm

To get a truly random number, you have to do something with isotopes. I don't remember exactly what.
I do stuff and break things. You know how it is.
Image
User avatar
Sonic
 
Posts: 1467
Joined: Tue Sep 01, 2009 6:18 pm
Location: America!!!

Re: Random Integer Code?

Postby KarateBrot » Thu Dec 10, 2009 9:10 pm

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.

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.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Random Integer Code?

Postby davidz40 » Thu Dec 10, 2009 10:25 pm

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
User avatar
davidz40
 
Posts: 438
Joined: Sun Sep 06, 2009 10:30 am

Re: Random Integer Code?

Postby Sonic » Fri Dec 11, 2009 4:57 pm

I actually saw a book of a millon random numbers. Some people have too much time on their hands.
I do stuff and break things. You know how it is.
Image
User avatar
Sonic
 
Posts: 1467
Joined: Tue Sep 01, 2009 6:18 pm
Location: America!!!

Re: Random Integer Code?

Postby RA2lover » Fri Dec 11, 2009 10:53 pm

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
User avatar
RA2lover
 
Posts: 607
Joined: Mon Aug 31, 2009 8:43 pm
Location: Brazil

Re: Random Integer Code?

Postby KarateBrot » Sat Dec 12, 2009 1:43 pm

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)
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Random Integer Code?

Postby Sonic » Mon Dec 14, 2009 6:45 pm

I'm no nuclear physiscist, but I but I beleive you mean when they "decay."
I do stuff and break things. You know how it is.
Image
User avatar
Sonic
 
Posts: 1467
Joined: Tue Sep 01, 2009 6:18 pm
Location: America!!!

Re: Random Integer Code?

Postby KarateBrot » Mon Dec 14, 2009 9:52 pm

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
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Random Integer Code?

Postby Antotabo » Thu Apr 15, 2010 1:47 am

Can someone tell me if Math.toInt is supposed to work in Phun?
And if not, what's the sinplest solution?
Antotabo
 
Posts: 54
Joined: Tue Sep 01, 2009 6:27 am

Re: Random Integer Code?

Postby Mystery » Thu Apr 15, 2010 5:21 am

Nope it doesn't work in phun.
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.
User avatar
Mystery
 
Posts: 2802
Joined: Thu Sep 03, 2009 1:16 pm
Location: Southern Australia

Re: Random Integer Code?

Postby Mr_Stabby » Thu Apr 15, 2010 12:59 pm

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)
Mr_Stabby
 
Posts: 155
Joined: Wed Dec 16, 2009 12:16 am

Re: Random Integer Code?

Postby niffirg1 » Tue Apr 20, 2010 1:03 am

Now this is one random Thread reopening........
User avatar
niffirg1
 
Posts: 376
Joined: Mon Aug 31, 2009 10:31 pm
Location: The Great American South!

Re: Random Integer Code?

Postby Nait » Sat Apr 24, 2010 10:18 am

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)
User avatar
Nait
 
Posts: 224
Joined: Fri Oct 30, 2009 1:56 am
Location: Eastern Russia, Vladivostok

Re: Random Integer Code?

Postby Nait » Sun Apr 25, 2010 8:10 am

EDITED
Here it is
Rating: rated 6.4
Filesize: 37.39 kB
Comments: 4
Ratings: 4
download
Last edited by Nait on Sun Apr 25, 2010 11:10 am, edited 1 time in total.
User avatar
Nait
 
Posts: 224
Joined: Fri Oct 30, 2009 1:56 am
Location: Eastern Russia, Vladivostok

Re: Random Integer Code?

Postby Mystery » Sun Apr 25, 2010 10:08 am

Nait wrote:Here it is
[scene]40744[/scene]

Nope i don't see it.
User avatar
Mystery
 
Posts: 2802
Joined: Thu Sep 03, 2009 1:16 pm
Location: Southern Australia

Re: Random Integer Code?

Postby Rideg » Sun May 02, 2010 10:49 pm

If you clone a circle 100 times upon itself what's deciding whether wich way each circle should go??(always wondered that :? )
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Next

Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 8 guests