# Random

I need to make the location of an objects appearance, the gravity applied on the object, and central force on the object to be random. I can’t seem to find how to do this, please help!

…didn’t I post that exact code :? Generally, why don’t you start out with things you can do and then work your way up? I mean if you worked with some vectors in a few smaller projects you will certainly learn a lot that should allow you to combine the code I posted and your knowledge then to create what you have in mind here.

I’m sorry but I thought I had that code working but it was not. I don’t really have time to work my way up. I am working on this for a project for school and it took most of my project time to get the jMonkey SDK to work because of compatibility issues. I understand the way vectors work but the only information online about this software is on this site and most of the wiki links don’t work.

Now when I try to implement the the randomizer it will not work. And I also don’t understand the physics listener. I need examples in code. I’m not looking for the code to just plug into my game but a whole program that uses this so I can look at the code and understand the way it functions. The tutorials on the listener are to vague.

:facepalm: Heres the solution:
[java]Random randomizer = new Random(System.currentTimeMillis());[/java]

Really? that figures, when you gave me the line earlier I thought that randomizer always had the - in front of it. I was close sans the Millis. I thought it would be written as
Random -randomizer = new Random(System.currentTimeSeconds()); but that was just a guess. Thanks normen.

Why don’t your teachers teach you java before letting you create falling boxes :? The “-” inverts the return value of the nextFloat() method.

you can also use FastMath.rand which has a precreated Random object instance

http://www.jmonkeyengine.com/doc/com/jme/math/FastMath.html#rand

Or use an XORShift random, they are crazy fast and even better than java default random.

[java]
class XORShift64 {
long x;
public XORShift64(long seed) {
x = seed==0 ? 0xdeadbeef : seed;
}
public long randomLong() {
x ^= (x <>> 35);
x ^= (x << 4);
return x;
}
}
[/java]

@jmassing Ok. I haven’t read the white paper thoroughly but is this kinda like a perlin noise or simplex noise function in that it’ll generate a series of random numbers based on a seed value? This seems pretty stonkin cool.

Did we really just take a thread where someone is still learning Java syntax and drop it into papers about random number generation?

@pspeed said: Did we really just take a thread where someone is still learning Java syntax and drop it into papers about random number generation? :)
Monkeys are awesome xD
Did we really just take a thread where someone is still learning Java syntax and drop it into papers about random number generation?

Yeah, I actually thought about that but since the class is so small I thought it might be appropriate as an example of Java syntax, so a little of both
It is also another lesson in itself. For some reason I dropped the forum editor ate a crucial line when pasting so it is also a lesson in “do your homework and check the references”
EDIT: Trying html escapes then: