# Random movment of an object?

**URL:** <https://forum.kirupa.com/t/random-movment-of-an-object/238721>\
**Category:** programming\
**Created:** [September 14, 2007, 8:16am UTC](https://forum.kirupa.com/t/random-movment-of-an-object/238721 "2007-09-14T08:16:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheDarkSide](https://avatars.discourse-cdn.com/v4/letter/t/85e7bf/32.png) [@TheDarkSide](https://forum.kirupa.com/u/TheDarkSide)\
**Post date:** [September 14, 2007, 8:16am UTC](https://forum.kirupa.com/t/random-movment-of-an-object/238721/1 "2007-09-14T08:16:15Z")

</div>

how do I go about implementing this?

```auto

**[SIZE=2][COLOR=#7f0055]**[SIZE=2][COLOR=#7f0055]**[SIZE=2][COLOR=#7f0055]import [/COLOR][/SIZE]**[SIZE=2][COLOR=#000000]com.ibm.invaders.*;[/COLOR][/SIZE]
[LEFT]**[SIZE=2][COLOR=#7f0055]import [/COLOR][/SIZE]**[SIZE=2][COLOR=#000000]java.util.*;[/COLOR][/SIZE][/LEFT]
 
 
**[SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE]****[SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE]**[SIZE=2][COLOR=#000000] MySpaceShip [/COLOR][/SIZE]**[SIZE=2][COLOR=#7f0055]extends[/COLOR][/SIZE]**[SIZE=2][COLOR=#000000] SpaceShip {[/COLOR][/SIZE]
 
[SIZE=2]Random rnd = [/SIZE]**[SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE]**[SIZE=2] Random ();[/SIZE]
**[SIZE=2][COLOR=#7f0055] private[/COLOR][/SIZE]**[SIZE=2] rnd;[/SIZE]
**[SIZE=2][COLOR=#7f0055] private [/COLOR][/SIZE]****[SIZE=2][COLOR=#7f0055]int [/COLOR][/SIZE]**[SIZE=2][COLOR=#0000c0]x[/COLOR][/SIZE][SIZE=2];[/SIZE]
**[SIZE=2][COLOR=#7f0055] private [/COLOR][/SIZE]****[SIZE=2][COLOR=#7f0055]int [/COLOR][/SIZE]**[SIZE=2][COLOR=#0000c0]y[/COLOR][/SIZE][SIZE=2];[/SIZE]
 
**[SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE]****[SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE]**[SIZE=2] initialize() {[/SIZE]
[SIZE=2] x = 0;[/SIZE]
[SIZE=2] y = 0;[/SIZE]
[SIZE=2] rnd = Random();[/SIZE]
[SIZE=2] x = rnd.nextInt();[/SIZE]
[SIZE=2] y = rnd.nextInt();[/SIZE]
[SIZE=2]}[/SIZE]
 
**[SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE]****[SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE]**[SIZE=2] move([/SIZE]**[SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE]**[SIZE=2] lastMoveTime) {[/SIZE]
[SIZE=2][COLOR=#0000c0] x[/COLOR][/SIZE][SIZE=2] = rnd.nextInt();[/SIZE]
[SIZE=2][COLOR=#0000c0] y[/COLOR][/SIZE][SIZE=2] = rnd.nextInt();[/SIZE]
 
[SIZE=2] }[/SIZE]
[SIZE=2]}[/SIZE]
 
[/COLOR][/SIZE]**
 
 
[/COLOR][/SIZE]**

```

[LEFT]is this right?[/LEFT]
