Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (429)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (468)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [QUICK QUESTION] Random numbers and outcomes  (Read 166 times)
0 Members and 1 Guest are viewing this topic.
Offline Genius Coder

Junior Member


Exp: 4 years



« Posted 2014-01-07 17:07:41 »

I have the following code selecting a random type of terrain to generate:

1  
2  
3  
4  
   
        public int type = 0;
   Random rand = new Random();
        type = rand.nextInt(3);


What are all the possible outcomes?
0,1,2 ?
1,2,3 ?
0,1,2,3 ?

Making games just got real...
Online StrideColossus
« Reply #1 - Posted 2014-01-07 17:09:39 »

From JavaDoc:
Quote
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
So 0...2
Offline Genius Coder

Junior Member


Exp: 4 years



« Reply #2 - Posted 2014-01-07 17:10:27 »

so 0 is included and the number in the brackets isnt'?

Making games just got real...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online StrideColossus
« Reply #3 - Posted 2014-01-07 17:11:45 »

so 0 is included and the number in the brackets isnt'?

correct
Offline opiop65

JGO Kernel


Medals: 131
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #4 - Posted 2014-01-07 17:13:57 »

Why didn't you just test out your code? Seriously, its as simple as throwing that code into a main method and printing out the result.

Everything in programming is 0 based (well some of it), so of course the "number in the brackets" won't be included.

Offline jmguillemette
« Reply #5 - Posted 2014-01-07 17:14:14 »

nextInt(int n)
          Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

-Taken from the javadoc

j.

-=Like a post.. give the author a medal!=-
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (6 views)
2014-04-24 19:00:44

xsi3rr4x (83 views)
2014-04-15 14:08:23

BurntPizza (75 views)
2014-04-14 23:46:01

UprightPath (86 views)
2014-04-14 13:39:50

UprightPath (69 views)
2014-04-14 13:35:47

Porlus (86 views)
2014-04-14 11:48:38

tom_mai78101 (109 views)
2014-04-10 00:04:31

BurntPizza (169 views)
2014-04-08 19:06:04

tom_mai78101 (265 views)
2014-04-05 09:34:39

trollwarrior1 (217 views)
2014-04-04 08:06:45
Escape Analysis
by Roquen
2014-04-25 06:22:13

List of Learning Resources
by SHC
2014-04-17 23:17:39

List of Learning Resources
by Longarmx
2014-04-07 23:14:44

Good Examples
by matheus23
2014-04-05 09:51:37

Good Examples
by Grunnt
2014-04-03 11:48:46

Good Examples
by Grunnt
2014-04-03 11:48:37

Good Examples
by matheus23
2014-04-01 14:40:51

Good Examples
by matheus23
2014-04-01 14:40:34
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!