Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Java
You last visited: Today at 06:07

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Java new Random

Discussion on Java new Random within the Java forum part of the Coders Den category.

Reply
 
Old   #1
 
strubelz's Avatar
 
elite*gold: 31
Join Date: Jan 2014
Posts: 310
Received Thanks: 55
Java new Random

Ich habe mal eine kurze Frage zur Random Klasse in Java. Ich habe das hier geschrieben:
Code:
public class BasicTask extends Task {

	Random rand = new Random();

	@Override
	public void run() {
	}

	int randomNumber(int min, int max) {
		return rand.nextInt((max - min) + 1) + min;
	}
}
Wenn ich das Random-Objekt nur einmal erstelle (ich will ja nicht zu viele unnötige Objekte erstellen) kann es dann passieren das sich wenn ich viele Zahlen damit generiere das ganze wiederholt. Ich hab im Internet leider nichts dazu gefunden.
strubelz is offline  
Old 07/30/2014, 00:04   #2
 
Schlüsselbein's Avatar
 
elite*gold: 0
Join Date: Feb 2013
Posts: 1,137
Received Thanks: 869
Quote:
Ich hab im Internet leider nichts dazu gefunden.
Erstes Ergebnis...


Ums kurz zu fassen: Echter Zufall steckt nie (mal von extra Hardware etc abgesehen) dahinter. Das ist je nach Anwendungsfall (für deinen so ziemlich sicher) aber Schnuppe.
Mehrere Objekte zu erstellen (ich gehe mal davon aus, dass Java dann intern einen neuen Seed verwendet), wird das Bild nie zufälliger machen (im besten Fall bleibt es gleich verteilt, sonst schlechter).
Schlüsselbein is offline  
Old 07/30/2014, 00:07   #3
 
strubelz's Avatar
 
elite*gold: 31
Join Date: Jan 2014
Posts: 310
Received Thanks: 55
Ok, danke, ich habe warscheinlich einfach nach den falschen Schlüsselwörtern gesucht.
strubelz is offline  
Reply


Similar Threads Similar Threads
Java Color.rgb(random,random,random)
05/19/2014 - Java - 4 Replies
Guten Abend liebe Community, ich habe ein Anliegen. Wie ist es möglich bei der Methode : setTextColor(Color.rgb(0,0,0)); anstatt (0,0,0) 3 random Integer zu verwenden wenn ja wie? Ich habe es mal so probiert: final Random r = new Random();
[JAVA Error] Could not create the java virtual machine
07/21/2013 - Technical Support - 10 Replies
Schönen Abend! Leider hat es sich aus einem unerfindlichen Grund ergeben, dass sobald ich die Minecraft.exe starten will die Errormeldung kommt. Die Tips auf Minecraft.net habe ich schon ohne Erfolg befolgt. Hoffe ihr könnt mir weiterhelfen... Mein PC:
[SALE] Random ISRO chars in random servers CHEAP, from 1$ to 3$
06/03/2012 - Silkroad Online Trading - 4 Replies
Hello, I want to sell all those chars very cheap for PayPal money from 1$ to 3$ , because I need some money to buy usb joystick to play FIFA on pc ^^ If you buy them all, I can sell all those chars for 15$!!! Contacts - skype: myntex2 I ACCEPT PAYPAL ONLY So let's start:



All times are GMT +2. The time now is 06:07.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.