Problem with random numbers
This is a snippet from a class
public class Cell {
private int index; //index of empire
private int xCoord; //X coordinate on the grid
private int yCoord; //Y coordinate on the grid
private double solidarity; //solidarity value of a cell
private double power; //power of a cell
private Random ran;
public Cell(int i, int x, int y) {
ran = new Random();
index = i;
xCoord = x;
yCoord = y;
solidarity = (double)ran.nextInt(100)/100.0;
......I make a couple hundred of these cells when i run the program and at random it seems, every Cell i create ends up having the same exact solidarity value, which really messes up my simulation. It seems to happen once every 5 runs or so. What could be causing this to happen?
In Java 1.4 Random is initalised with the time.
Thus if you create many Random objects at the same time, they will generate the same "random" values.
In Java 5.0 it prevents this behaviour.
In your case the simplest thing to do is to create one Random and share it.
Or you could create your own random seed using i,x,y for example. (thus ensure the random seed is different for each cell)
Similar Messages
-
Problem with Purchase Order creation with Random numbers .
Hi Experts
Currently i am facing an issue with Bapi BAPI_PO_CREATE1 to create Purchase order with random numbers for example items 1, 3,5.
Please let me know the settings .
Thanks in AdvanceHi Neha,
A reset of the release strategy only takes place if
- the changeability of the release indicator is set to '4' in
case of a purchase requisition and '4' or '6' in case of
another purchasing document (purchase order, request for
quotation, contract, scheduling agreement),
- the document is still subject to the previous release
strategy,
- the new TOTAL NET ORDER VALUE is higher than the old one.
The total net order value is linked to CEKKO-GNETW for a purchase order,
CEBAN-GSWRT for a purchase requisition item-wise release and CEBAN-GFWRT
for a purchase requisition overall release.
If you have maintained a Tolerance for value changes during release
(V_161S-TLFAE), the release strategy is reset when the value of the
document is higher than the percentage you have specified and if the
document is still subject to the previous release strategy.
Review the SAP note 365604 and 493900 for more
information about Release strategy.
Regards,
Ashwini. -
Application Express 3.1 + BI-Publisher + problem with formating numbers
Hello together!
I use the Oracle BI Publisher Template Builder for Word (10.1.3.4) to generate RTF-Templates. I upload these templates in Oracle Apex (Advanced support-->BI-Publisher/OC4J as print service).
It works well, but I have a problem with formating numbers.
In Template Builder I define following number formats, for example: #.##0 for numbers like 1.454.234 and #.##0,00 for numbers like 54,80
In Template-Builder Preview it looks well.
But whatever I do, in use with Oracle Apex dots and comma are allready interchances in the printout.
That means,
1.454.234 become 1,454,234 in PDF-Report
54,80 become 54.80 in PDF-Report
Other than that, the layout is exactly the same like in Template Builder defined.
What's wrong?
Do I have to change any country parameter?
JulianeI also had the same problem. I tried with normal formating of 99g99g999d99 instead of ##,##,##0.00 and it has resulted correct way.
-
Problem with page numbering in Acrobat XI Pro
Hello community,
I got a problem with page numbering with certain documents in Acrobat XI Pro.
The next error comes up:
Translated in English:
There is an error occured when getting up of page-content.
This is occured with certain pdf-documents (i cannot uploading this file).
Is someone have similar problem, or has someone hev a sollution for this?
Greetings,
BartThis usually means the file is corrupt, probably because it was not created
using a standard application like Adobe Acrobat. -
I'm having problems with random contacts disappearing from icloud. I have a saved text from a contact that displays her info but when I look for her in contacts it's missing.
It is locked to your sisters carrier.
She would have to ask her carrier if they unlock iPhones and if she qualifies for this service. -
Working with random numbers and probabilities
Hi again,
i am working with random numbers at the moment.
in the first step i do create a random number between 3 and 8 which is stored to a variable.
set myVAR1 to random number from 3 to 8 as integer
Lets assume myVAR1 is 5
Now i want to select 5 numbers out of number pool from 1 to 8. Each number should be pickable only once.
How would i realize that ?
I guess i need some kind of pool, array and then select 5 out of this array, but i am not sure about the syntax.
In best case i would like to add probabilities to those 8 numbers in the pool.
i.e.
1 (5%),2(5%),3(20%),4(10%),5(20%),6(10%),7(15%),8(15%)
any help is heavily appreciated
best regards
fidelHello fidel,
For selecting unique numbers from given pool, try something like this.
--SCRIPT 1
(* select unique numbers from pool *)
set pool to {1, 2, 3, 4, 5, 6, 7, 8} -- number pool
set n to random number from 3 to 8 -- selection count
return {n, random(n, pool)}
on random(n, pool)
set kk to {}
repeat with i from 1 to count pool
set end of kk to i
end repeat
set rr to {}
repeat n times
set k to kk's some integer
set kk's item k to false
set end of rr to pool's item k
end repeat
return rr
end random
--END OF SCRIPT 1
For introducing selection weight of each number in the pool, you may try the below.
--SCRIPT 2
(* select unique numbers from pool with stochastic weights *)
set pool to {1, 2, 3, 4, 5, 6, 7, 8} -- number pool
set weights to {5, 5, 20, 10, 20, 10, 15, 15} -- selection weight
set n to random number from 3 to 8 -- selection count
return {n, random(n, pool, weights)}
on random(n, pool, weights)
script o
property ww : weights
property pp : {}
property kk : {}
property rr : {}
repeat with i from 1 to count pool
repeat my ww's item i times
set end of my pp to pool's item i
end repeat
end repeat
repeat with i from 1 to count my pp
set end of my kk to i
end repeat
repeat n times
set k to my kk's some integer
set end of my rr to my pp's item k
set j to 0
set i to 1
repeat with w in my ww
set j to j + w
if k > j then
set i to j + 1
else
repeat with h from i to j
set my kk's item h to false
end repeat
set i to 1
exit repeat
end if
end repeat
end repeat
return my rr's contents
end script
tell o to run
end random
--END OF SCRIPT 2
Hope this may help,
H
Message was edited by: Hiroto -
Problem with random number generation
hey forum, i wonder if anyone can help me out with a small problem with my university coursework (yep its homework!!!)
heres my problem, i am writing one of them 8 puzzle problems (the one based around sam lloyds 15 puzzler), i can successfully generate one random sequence of numbers with no duplicates, but whenever i call the random method again it keeps producing the same results
heres the code
in my main class file
if(e.getSource() == randomButton) {
new RandomPuzzle();
System.out.println(random.randState);
//startStateString = new RandomPuzzle();
}heres my number generator class file
import java.util.Random;
import java.io.*;
public class RandomPuzzle
/** Base Random number generator */
Random rn = new Random();
/** Puzzle holder */
byte b[];
long number = 0;
String randState = "";
/** Default constructor */
public RandomPuzzle() {
rn.setSeed(number);
b = new byte[9];
randState = randomString();
/** Provide range for generation */
public int rand(int lo, int hi) {
int n = hi - lo + 1;
int i = rn.nextInt() % n;
if (i < 0)
i = -i;
return lo + i;
/** Set size for array */
public int rand( int hi){
int n = hi;
return n;
/** Check for duplicate values within the same configuration */
boolean valueExists( byte value ) {
int i = b.length;
boolean exists = false;
for( int j = 0; j < i; j++ ){
if( b[j] == value )
exists = true;
return exists;
/** returns the actual string */
public String randomString(int lo, int hi) {
int n = rand( 9 );
//boolean valueEntered = false;
for (int i = 0; i < 9; i++) {
boolean valueEntered = false;
byte temp = (byte)rand('0', '8');
while( valueEntered == false ) {
if( !valueExists( temp ) ) {
b[i] = temp;
valueEntered = true;
else
temp = (byte)rand('0', '8');
return new String(b, 0);
/** calls above function */
public String randomString() {
return randomString(0, 8);
}i've tried for hours to work this out, but i am stumped. if anyone can point me in the right direction, maybe point out the problem code and give one or two tips i would be forever in your debt
thanx in advance
korbitzthanx for the help paulcw, but when i removed the seed code it done the same
but i added this to my main class and now it works fine
if(e.getSource() == randomButton) {
RandomPuzzle temp = new RandomPuzzle();
System.out.println(temp.randState);
//startStateString = new RandomPuzzle();
}thanx again for your help -
Problems with random shutdown after replacing a swollen battery
Hello all,
Perhaps one of you can help with this issue.
I'm using a Macbook Pro 17" mid-2007 model. A few months ago, the power disconnected from the machine when the battery had already run down and the machine did a hard shutdown. When I booted it back up there were serious problems with the display. Eventually it stopped working altogether. I took it for service and it was determined to by the NVIDIA graphics processor problem, so Apple replaced my motherboard.
When I got the machine back from servicing, there was a rattle in the right fan that gradually got worse. After a while the touchpad button stopped depressing in the center. I also experienced several random shutdowns while operating on battery power. I learned about the swelling battery issue with macbooks and ordered a replacement. By the time the replacement battery arrived my original battery was quite swollen. I'm concerned that the swelling battery may have warped the case a bit, leading to the fan noise.
I have now replaced the battery, but I'm still experiencing random shutdowns after 20+ minutes of use on battery power. I have done the RSS tests that were recommended in other forums and there doesn't seem to be any random shutdown problems when I'm plugged in -- only under battery power. My understanding is that a swelling battery can sometimes cause the battery to disengage from the electrical contacts on the MB, causing a sudden shutdown. I'm wondering why the problem is persisting now with a new battery? After one random shutdown, I tried to power up again using the battery, while pushing the battery into place at various angles, but I couldn't find any angle that would give power to the machine. The fan noise is also still present.
Can anyone offer an explanation or advise on any methods to overcome these random shutdowns? I have checked the console and the machine isn't registering any error when it shuts down, although when it restarts it says "DirectoryService[35] Improper shutdown detected"Yep, it is video (or: or audio for video) so unless you're sure you need it (because you work or will work with the DVC Pro HD video/audio codec), you can remove the plug from its' folder and put it in your documents folder (don't trash it, I have no idea if it is necessary for non-DVC Pro HD users to have it installed too).
The WWW is littered with posts from people encountering bugs and crashreports with DVCPROHDAudio.plugin as the main suspect. Most of those posts seem to be from video people rather than audio folks.
http://www.google.nl/search?q=DVCPROHDAudio.plugin&ie=utf-8&oe=utf-8&aq=t&rls=or g.mozilla:en-US:official&client=firefox-a
But, if you get crashes and you see this one mentioned in the report, disable it, restart, and see if the problem's gone. -
Problem with decimal numbers..
hi i posted the other day with a problem I had. I thought it was all sorted but I have just realised that there is another problem.
I have the following code for an applet:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class TextFieldExample extends Applet implements ActionListener {
TextField textInput;
String text = "";
public void init() {
textInput = new TextField (20);
add(textInput);
textInput.addActionListener(this);
public void actionPerformed(ActionEvent e) {
text = textInput.getText();
repaint();
public void paint(Graphics g) {
int x = Integer.parseInt(text);
double y = Math.abs(x);
g.drawString("You wrote " + text,20,500);
g.drawString("The absolute value is: " + y,20,100);
I am trying to do the applet so when you type in an angle, it tell you the sine, cosine etc. I can get it to work with whole numbers like 1,10,300, but it won't work when i try to use decimal numbers. Can anyone help?
Thnk you in advance!
Hi,
you are using Integer.parseInt() to convert the input, so it will only work if the text is an integer. Use Double.parseDouble() instead.
Andre -
How to fill an array with random numbers
Can anybody tell me how I can fill an array with thousand random numbers between 0 and 10000?
import java.util.Random;
class random
static int[] bull(int size) {
int[] numbers = new int[size];
Random select = new Random();
for(int i=0;i<numbers.length;i++) {
harris:
for(;;) {
int trelos=select.nextInt(10000);
numbers=trelos;
for(int j=0;j<i;j++) {
if(trelos==numbers[j])
continue harris;
numbers[i]=trelos;
break;
return numbers;
/*This method fills an array with numbers and there is no possibility two numbers to be the
same*/
/*The following method is a simpler method,but it is possible two numbers to be the same*/
static int[] bull2(int size) {
int[] numbers = new int[size];
Random select = new Random();
for(int i=0;i<numbers.length;i++)
numbers[i]=select.nextInt(9);
return numbers;
public static void main(String[] args) {
int[] nikos = random.bull(10);
int[] nikos2 = random.bull2(10);
for(int i=0;i<nikos.length;i++)
System.out.println(nikos[i]);
for(int i=0;i<nikos2.length;i++)
System.out.println(nikos2[i]); -
Problems with line numbers (building via ant).
We use ant for our builds and are having a problem with getting line numbers into call stacks. When running on linux we do not get the lines for our projects (not all projects have debug option), just (Unknown Source), however we do see line numbers for the tib jars. Eclipse is fine, we can see all line numbers as appropriate.
I have tried "lines", "lines,source" and "lines,var,source" - all build a different sized jar which suggest something is getting added. However as we see line nums for tib it suggests it's some strange java runtime option. We're using sunjdk 1.5.10 and also jrockit.
Any ideas/answers most appreciated.
Many thanks, Declan
Ant task
<target name="compile" depends="init">
<javac target="1.5" destdir="${classes}" debug="on" debuglevel="lines,source">
<src path="${src}"/>
<classpath refid="default.classpath"/>
</javac>
<javac target="1.5" destdir="${classes-test}" debug="on" debuglevel="lines,source">
<src path="${testsrc}"/>
<classpath refid="default.classpath"/>
<classpath location="${classes}"/>
</javac>
</target>
Example output
java.lang.IllegalArgumentException: Field data is null
at com.tibco.tibrv.TibrvMsg._addImpl(TibrvMsg.java:1503)
at com.tibco.tibrv.TibrvMsg.add(TibrvMsg.java:1020)
at com.lehman.fid.jdt.channel.tibrv.TibrvMessage.putObject(Unknown Source)
at com.lehman.cmd.etrading.orderbook.dp.DefaultDepthPublisher.buildSubMessage(Unknown Source)
at com.lehman.cmd.etrading.orderbook.dp.DefaultDepthPublisher.buildSubMessage(Unknown Source)
at com.lehman.cmd.etrading.orderbook.dp.DefaultDepthPublisher.publishDepth(Unknown Source)
Cmd line
VM_OPTS="-Dlogfile=../../log/CmdOrderBook.log"
VM_OPTS="${VM_OPTS} -Dcom.sun.management.jmxremote"
VM_OPTS="${VM_OPTS} -Dcom.sun.management.jmxremote.authenticate=false"
VM_OPTS="${VM_OPTS} -Dcom.sun.management.jmxremote.password=false"
VM_OPTS="${VM_OPTS} -Dcom.sun.management.jmxremote.ssl=false"
PARAMS="-springcfg orderbook-context.xml -instancename CmdOrderBook"
exec ${JAVA_HOME}/bin/java -DappInstance=CmdOrderBook -server -Xmx500M -Xms250M -Xincgc ${VM_OPTS} com.lehman.cmd.etrading.orderbook.CommoditiesOrderBook ${PARAMS} >> ../../log/Cm
dOrderBook.out 2>&1We use ant for our builds and are having a problem with getting line numbers into call stacks. When running on linux we do not get the lines for our projects (not all projects have debug option), just (Unknown Source), however we do see line numbers for the tib jars. Eclipse is fine, we can see all line numbers as appropriate.
I have tried "lines", "lines,source" and "lines,var,source" - all build a different sized jar which suggest something is getting added. However as we see line nums for tib it suggests it's some strange java runtime option. We're using sunjdk 1.5.10 and also jrockit.
Any ideas/answers most appreciated.
Many thanks, Declan
Ant task
<target name="compile" depends="init">
<javac target="1.5" destdir="${classes}" debug="on" debuglevel="lines,source">
<src path="${src}"/>
<classpath refid="default.classpath"/>
</javac>
<javac target="1.5" destdir="${classes-test}" debug="on" debuglevel="lines,source">
<src path="${testsrc}"/>
<classpath refid="default.classpath"/>
<classpath location="${classes}"/>
</javac>
</target>
Example output
java.lang.IllegalArgumentException: Field data is null
at com.tibco.tibrv.TibrvMsg._addImpl(TibrvMsg.java:1503)
at com.tibco.tibrv.TibrvMsg.add(TibrvMsg.java:1020)
at com.lehman.fid.jdt.channel.tibrv.TibrvMessage.putObject(Unknown Source)
at com.lehman.cmd.etrading.orderbook.dp.DefaultDepthPublisher.buildSubMessage(Unknown Source)
at com.lehman.cmd.etrading.orderbook.dp.DefaultDepthPublisher.buildSubMessage(Unknown Source)
at com.lehman.cmd.etrading.orderbook.dp.DefaultDepthPublisher.publishDepth(Unknown Source)
Cmd line
VM_OPTS="-Dlogfile=../../log/CmdOrderBook.log"
VM_OPTS="${VM_OPTS} -Dcom.sun.management.jmxremote"
VM_OPTS="${VM_OPTS} -Dcom.sun.management.jmxremote.authenticate=false"
VM_OPTS="${VM_OPTS} -Dcom.sun.management.jmxremote.password=false"
VM_OPTS="${VM_OPTS} -Dcom.sun.management.jmxremote.ssl=false"
PARAMS="-springcfg orderbook-context.xml -instancename CmdOrderBook"
exec ${JAVA_HOME}/bin/java -DappInstance=CmdOrderBook -server -Xmx500M -Xms250M -Xincgc ${VM_OPTS} com.lehman.cmd.etrading.orderbook.CommoditiesOrderBook ${PARAMS} >> ../../log/Cm
dOrderBook.out 2>&1 -
I recently upgraded to RoboHelp 8 and I opened my old project to update an HTML online help. Whenever I generated the online help and I clicked to view the result on the PC with RoboHelp 8, everything looked fine. Then, I copied all generated files to a server to be part of a web application. Today, I found out that when I viewed the online help on the server using the same PC with RoboHelp 8, all numbers of numbered lists displayed against the left side of the main body of the help are not displayed correctly. Part of each number got chopped off. Again, if I go to the !SSL! folder and display the online help that I generated, it looks fine. I also found out that when I used another PC to view the same online help file from the server, all the numbered lists looked fine. The PC with RoboHelp 8 runs with Windows 7 Enterprise 64 bit and the PC that I could see the numbered lists correctly runs with Windows 7 Professional 64bit. I don't understand why the two PCs do not display the same online help the same way. I asked someone to use his PC running Windows XP with IE7 and the numbered lists were not displayed correctly.
I read some discussions and there were a suggestion to use the "Convert RoboHelp Edited Topics to HTML" option to correct some problems with RoboHelp 8, so I tried it and it seemed to help. When using the option, I could see the numbered lists correctly. I am still wondering why two PCs did not display the same online help the same way. I am trying to see if there is an option with IE that can be used to solve this problem instead of deploying a new version of the online help. Does anyone know what the "Convert RoboHelp Edited Topics to HTML" option actually does. Will I be introducing more problems using this option?
RJThank you very much for replying. The convert option seems to fix the problem and I will probably redo my lists later because I did not seem to be able to make any changes to them.
I am still puzzled why one PC running the 64 bit Windows 7 Pro is able to display all numbered lists correctly and the other PC running the 64 bit Windows 7 Enterprise using the same version of Internet Explorer is not able to display any numbered lists correctly. I looked around with all the options for Internet Explorer and they are the same. I also noticed that when I used Google Chrome and FireFox, the numbered lists are displayed fine. I also noticed that if all the online help files are saved locally on the PC that is not able to displayed the numbered lists correctly, when I display the online help, the numbered lists look fine. It does not work when displaying the online help from a server. If you know an option that might make the online help to work properly with Internet Explorer without deploying a new version, please let me know.
Thanks,
RJ -
hi i need to generate 2 random numbers from array list . and then take out that two numbers from list.
String[] plcard = { "AC", "KC", "QC", "JC",
"10C", "9C", "8C", "7C","6C","5C","4C","3C","2C", "AD", "KD", "QD", "JD",
"10D", "9D", "8D", "7D","6D","5D","4D","3D","2D", "AS", "KS", "QS", "JS",
"10S", "9S", "8S", "7S","6S","5S","4S","3S","2S", "AH", "KH", "QH", "JH",
"10H", "9H", "8H", "7H","6H","5H","4H","3H","2H",};
this is the list if someone can help me i would appreciate
thanks in advancehaha, never noticed the .shuffle(List) method!
maybe java is getting too convenient (just kidding)?
i never wrote a card game.
how would the more programmingly gifted of us do this?
this is my shot at it for what its worth...
public class Card{
public Card(int rank, int suit){
this.rank = rank;
this.suit = suit;
int rank (or String i suppose)
int suit;
static final club = 1;
static final spade = 2;
static final heart = 3;
static final diamond = 4;
public class Shuffler{
public Shuffler(){
int NumOfDecks = 1;
Vector ShuffledDeck;
// num of decks
for(int i = 0; i < NumOfDecks){
// 4 suits
for(int j = 0; j < 4; j++){
// 13 ranks
for(int k = 0; k < 13; k++){
ShuffledDeck.add(new Card(k, j));
} // suits
} // num of decks
Collections.shuffle(ShuffledDeck);
// Done?
} -
is there a way of creating a series of 6 random numbers from 1-9 without repeating a single number? i have currently developed the following method which so far generates a random number excluding zero, but ive no idea of how to ensure that i get different numbers everytime....
private int randomNumber () {
int num;
do {
num = (int) (Math.random()*10);
} while (num == 0);
return num;
}anyone got any ideas?use this insteadRandom rand = new Random();
// Random integers that range from from 0 to n
int n = 10;
int i = rand.nextInt(n+1); -
Is anyone else having terrible problems with random freezing?
For the most part, Lion runs nicely for me. It's faster, has some neat features... but that's only when it actually runs.
I have some terrible problems with freezing, sometimes as early as typing in my password to login to my profile on my MacBook Pro. Just now it froze twice (after booting up), and both times I had to turn it off and power it back on again. The first freeze was caused because I moved my mouse a little bit on the screen.
I understand that new versions of OSs have bugs to iron out, but this seems extremely over the top. Is anyone else having issues with freezing this bad? I'm afraid to use any of the cool new features of Lion because my computer has proven it can freeze for the absolute tiniest things.Tons of threads like this, the solution is to disable automatic graphic switching. Personally I'm doing automatic login, allows me to boot in before the freeze occurs when it happens at login. Crazy.
Maybe you are looking for
-
ITunes 12.1.1.4 and iOS 8.2 Unable to Sort Videos!
I'm using a Windows 7 64-bit OS. I just upgraded iTunes to version 12.1.1.4, as well as my iPad 2 to iOS version 8.2. As a result of these upgrades, I now find that the TV shows downloaded to my iPad are no longer sorted according to the name of the
-
Cannot open pictures in iphoto
I went to download pictures to iphoto on my MacBook Pro and all i get is the hour glass circle. The iphoto menu does not come up either.
-
I have issue with a query as follows. It is not using index when i keep a function on the left hand side of comparison in where condition. But when I remove the function it is using index. With BLC AS Name Null?
-
during my installation, there is Error pop up..! "internal error 2356. data1.cab" hmm anyone know how to fix this problem? please help... thanks
-
Hi forum: I want to explain you my problem, i made one login development in SAP Enterprise Portal and in this develop i have created a cookie for ISA, for login me in the ISA Shop the problem is that i can´t do it again, i mean loggin me into de