Need hep with random numbers
Me and my friends play magic the gathering. There is a mode called planechase. I wont to build a program that simulates this. so it will randomize 82 numbers then store them in the order generated. the game also involves drawing the next card, revealig
next card, and putting cards on bottom. Any help given will be greatly appreciated. I'm just trying to get an idea of where to start.
Hello,
Thank you for your post.
I am afraid that the issue is out of support range of VS General Question forum which mainly discusses the usage issue of Visual Studio IDE such as
WPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System
and Visual Studio Editor.
I am moving your question to the moderator forum ("Where is the forum for..?"). The owner of the forum will direct you to a right
forum.
In my opinion, you my consult on
Visual Studio Language Forums: http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=vslanguages
Best regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.
Similar Messages
-
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?
} -
Need Help with random numbers, please help
Hi guys;
I need your help for a school project. I need to generate a random number from 1.0 to 2.0. How would I do that?
Regards,http://java.sun.com/j2se/1.3/docs/api/java/util/Random.html#nextFloat()
-
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 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. -
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]); -
I need help with random number in GUI
hello
i have home work about the random number with gui. and i hope that you can help me doin this application. and thank you very much
Q1)
Write an application that generates random numbers. The application consists of one JFrame,
with two text fields (see the figures) and a button. When the user clicks on the button, the
program should generate a random number between the minimum and the maximum numbers
entered in the text fields. The font of the number should be in red, size 100, bold and italic.
Moreover, if the user clicks on the generated number (or around it), the color of the background
should be changed to another random color. The possible colors are red, green blue , black ,cyan
and gray.
Notes:
�The JFrame size is 40 by 200
�The text fields size is 10
this is a sample how should the programe look like.
http://img235.imageshack.us/img235/9680/outputgo3.jpg
Message was edited by:
jave_coolsee java.util.Random
-
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); -
Need some help with Random numbers.
Hey,
Im not sure why this is not working....
public static void main(String[] args) {
System.out.printf ("Enter n:\n");
Scanner keyboard = new Scanner (System.in);
int n1=0,
n2=0,
n3=0,
n4=0,
n5=0,
n6=0,
facevalue,
x1,
count = 0;
double x = keyboard.nextDouble ();
x1 = rollDie ();
System.out.println(x1);
while (count < x) {
facevalue = 1+x1.nextInt (6);
if (facevalue == 1) n1++;
if (facevalue == 2) n2++;
if (facevalue == 3) n3++;
if (facevalue == 4) n4++;
if (facevalue == 5) n5++;
if (facevalue == 6) n6++;
count += 1 ; }
System.out.printf ("%d %d %d %d %d %d\n",n1,n2,n3,n4,n5,n6);
int maxValue = n1;
if (maxValue < n2)
maxValue = n2;
if (maxValue < n3)
maxValue = n3;
if (maxValue < n4)
maxValue = n4;
if (maxValue < n5)
maxValue = n5;
if (maxValue < n6)
maxValue = n6;
System.out.printf ("Max %d\n",maxValue);
System.out.printf ("Avg %f\n",
1/x*(n1*1+n2*2+n3*3+n4*4+n5*5+n6*6));
public static int rollDie (){
int x1 = (int) Math.random();
System.out.println(x1);
return x1;
}The random number is always 0. Also there is an error at facevalue = 1+x1.nextInt (6); That says 'int cannot be dereferenced.' Please help! thanks!Also, this particular assignment seems to be a good time for you to learn about arrays. Look for a tutorial on java arrays. This will reduce your lines of code by 75%.
What I mean is, you have 6 different variables to hold the total number of times each roll occurred. Instead, you could have a length-6 array:
//declaring
int[] tally = new int[6];
//adding one to the tally
int nextRoll = random.nextInt(6) + 1;
tally[nextRoll-1]++; -
Need help with skype numbers....urgent please!
Question regarding skype numbers..... So i plan to buy hongkong skype number,......say for example + 852 8192 6362, and if im right , i can receive the calls on my PC /desktop, etc. But what about if im traveling , for few days to mainland china or london , will my family still be able to call the same number with appropriate county code, n will i continue to recive calls on my PC. { *Example calling me in china +8621 8192 6362 } In short, can my family call my anywhere in the world by using proper country codes, or is skype number limited to hongkong only, I travel alot, and cant change numbers frequently. Thanks....
Hi, ajamal786, and welcome to the Community,
Yes, your one Skype Number travels with your account regardless of wherever you are. Such is the beauty of a Skype Number: people can call you on the number you set up, which in theory would be a local call to them depending upon the availability of numbers from which you can choose (my Skype Number exchange is a few townships away, but still a local call), and reach you on Skype.
So, no need to change a Skype Number.
Elaine
Was your question answered? Please click on the Accept as a Solution link so everyone can quickly find what works! Like a post or want to say, "Thank You" - ?? Click on the Kudos button!
Trustworthy information: Brian Krebs: 3 Basic Rules for Online Safety and Consumer Reports: Guide to Internet Security Online Safety Tip: Change your passwords often! -
Problem in creation of File with random numbers
hi all,
i have written a function which generates random num,ber and stores in a text file.
public static void main(String[ ] args) {
int count=0;
System.out.println("Generate Files");
Random R=new Random();
File F= new File("C:/e.cartesian");
try{
FileWriter fw=new FileWriter(F);
int c=0;
int rand=200;
int l=0;
for(int i=0;i<3;i++)
{ for(int j=0;j<5;j++)
{ for(int k=0;k<80;k++)
c+=1;
double d=R.nextDouble()*100;
Double D=new Double(d);
int dtoi=D.intValue();
float itof=(dtoi/(float)100.0)+R.nextInt(200)+l;
Float f=new Float(itof);
fw.write(f.toString()+" ");
System.out.println(f.toString());
fw.write("\n");
count+=1;
l+=200;
System.out.println("Count==>"+count);
}catch(IOException e){}
Problem is , if i run this code with condition k<79 or some other smaller value than 80 it doesnt save any value in text file.If you close the file after writing it works: fw.close();
-
Newbie needing help with code numbers and if-else
I'm 100% new to any kind of programming and in my 4th week of an Intro to Java class. It's also an on-line class so my helpful resources are quite limited. I have spent close to 10 hours on my class project working out P-code and the java code itself, but I'm having some difficulty because the project seems to be much more advanced that the examples in the book that appear to only be partly directly related to this assignment. I have finally come to a point where I am unable to fix the mistakes that still show up. I'm not trying to get anyone to do my assignment for me, I'm only trying to get some help on what I'm missing. I want to learn, not cheat.
Okay, I have an assignment that, in a nutshell, is a cash register. JOptionPane prompts the user to enter a product code that represents a product with a specific price. Another box asks for the quanity then displays the cost, tax and then the total amount plus tax, formatted in dollars and cents. It then repeats until a sentinel of "999" is entered, and then another box displays the total items sold for the day, amount of merchandise sold, tax charged, and the total amount acquired for the day. If a non-valid code is entered, I should prompt the user to try again.
I have this down to 6 errors, with one of the errors being the same error 5 times. Here are the errors:
C:\PROGRA~1\XINOXS~1\JCREAT~1\MyProjects\Sales.java:50: 'else' without 'if'
else //if invalid code entered, output message
^
C:\PROGRA~1\XINOXS~1\JCREAT~1\MyProjects\Sales.java:39: unexpected type
required: variable
found : value
100 = 2.98;
^
C:\PROGRA~1\XINOXS~1\JCREAT~1\MyProjects\Sales.java:41: unexpected type
required: variable
found : value
200 = 4.50;
^
C:\PROGRA~1\XINOXS~1\JCREAT~1\MyProjects\Sales.java:43: unexpected type
required: variable
found : value
300 = 6.79;
^
C:\PROGRA~1\XINOXS~1\JCREAT~1\MyProjects\Sales.java:45: unexpected type
required: variable
found : value
400 = 5.29;
^
C:\PROGRA~1\XINOXS~1\JCREAT~1\MyProjects\Sales.java:47: unexpected type
required: variable
found : value
500 = 7.20;
^
And finally, here is my code. Please be gentle with the criticism. I've really put a lot into it and would appreciate any help. Thanks in advance.
import java.text.NumberFormat; // class for numeric formating from page 178
import javax.swing.JOptionPane; // class for JOptionOPane
public class Sales {
//main method begins execution ofJava Application
public static void main( String args[] )
double quantity; // total of items purchased
double tax; // total of tax
double value; // total cost of all items before tax
double total; // total of items including tax
double totValue; // daily value counter
double totTax; // daily tax counter
double totTotal; // daily total amount collected (+tax) counter
double item; //
String input; // user-entered value
String output; // output string
String itemString; // item code entered by user
String quantityString; // quantity entered by user
// initialization phase
quantity = 0; // initialize counter for items purchased
// get first code from user
itemString = JOptionPane.showInputDialog(
"Enter item code:" );
// convert itemString to double
item = Double.parseDouble ( itemString );
// loop until sentinel value read from user
while ( item != 999 ) {
// converting code to amount using if statements
if ( item == 100 )
100 = 2.98;
if ( item == 200 )
200 = 4.50;
if ( item == 300 )
300 = 6.79;
if ( item == 400 )
400 = 5.29;
if ( item == 500 )
500 = 7.20;
else //if invalid code entered, output message
JOptionPane.showMessageDialog( null, "Invalid code entered, please try again!",
"Item Code", JOptionPane.INFORMATION_MESSAGE );
} // end if
} // end while
// get quantity of item user
itemString = JOptionPane.showInputDialog(
"Enter quantity:" );
// convert quantityString to int
quantity = Double.parseDouble ( quantityString );
// add quantity to quantity
quantity = quantity + quantity;
// calculation time! value
value = quantity * item;
// calc tax
tax = value * .07;
// calc total
total = tax + value;
//add totals to counter
totValue = totValue + value;
totTax = totTax + tax;
totTotal = totTotal + total;
// display the results of purchase
JOptionPane.showMessageDialog( null, "Amount: " + value +
"\nTax: " + tax + "\nTotal: " + total, "Sale", JOptionPane.INFORMATION_MESSAGE );
// get next code from user
itemString = JOptionPane.showInputDialog(
"Enter item code:" );
// If sentinel value reached
if ( item == 999 ) {
// display the daily totals
JOptionPane.showMessageDialog( null, "Total amount of items sold today: " + quantity +
"\nValue of ites sold today: " + totValue + "\nTotal tax collected today: " + totTax +
"\nTotal Amount collected today: " + totTotal, "Totals", JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 ); // terminate application
} // end sentinel
} // end message
} // end class SalesHere you go. I haven't tested this but it does compile. I've put in a 'few helpful hints'.
import java.text.NumberFormat; // class for numeric formating from page 178
import javax.swing.JOptionPane; // class for JOptionOPane
public class TestTextFind {
//main method begins execution ofJava Application
public static void main( String args[] )
double quantity; // total of items purchased
double tax; // total of tax
double value; // total cost of all items before tax
double total; // total of items including tax
// double totValue; // daily value counter
// double totTax; // daily tax counter
// double totTotal; // daily total amount collected (+tax) counter
// Always initialise your numbers unless you have a good reason not too
double totValue = 0; // daily value counter
double totTax = 0; // daily tax counter
double totTotal = 0; // daily total amount collected (+tax) counter
double itemCode;
double item = 0;
String itemCodeString; // item code entered by user
String quantityString; // quantity entered by user
// initialization phase
quantity = 0; // initialize counter for items purchased
// get first code from user
itemCodeString = JOptionPane.showInputDialog("Enter item code:" );
// convert itemString to double
itemCode = Double.parseDouble ( itemCodeString );
// loop until sentinel value read from user
while ( itemCode != 999 ) {
* 1. variable item mightnot have been initialised
* You had item and itemCode the wrong way round.
* You are supposed to be checking itemCode but setting the value
* for item
// converting code to amount using if statements
if ( item == 100 )
{itemCode = 2.98;}
else if ( item == 200 )
{itemCode = 4.50;}
else if ( item == 300 )
{itemCode = 6.79;}
else if ( item == 400 )
{itemCode = 5.29;}
else if ( item == 500 )
{itemCode = 7.20;}
else {//if invalid code entered, output message
JOptionPane.showMessageDialog( null, "Invalid code entered, please try again!",
"Item Code", JOptionPane.INFORMATION_MESSAGE );
} // end if
} // end while
// get quantity of item user
itemCodeString = JOptionPane.showInputDialog("Enter quantity:" );
* 2.
* You have declared quantityString here but you never give it a value.
* I think this should be itemCodeString shouldnt it???
* Or should you change itemCodeString above to quantityString?
// convert quantityString to int
// quantity = Double.parseDouble ( quantityString ); // old code
quantity = Double.parseDouble ( itemCodeString );
// add quantity to quantity
quantity = quantity + quantity;
// calculation time! value
value = quantity * itemCode;
// calc tax
tax = value * .07;
// calc total
total = tax + value;
//add totals to counter
* 3. 4. and 5.
* With the following you have not assigned the 'total' variables a value
* so in effect you are saying eg. "total = null + 10". Thats why an error is
* raised. If you look at your declaration i have assigned them an initial
* value of 0.
totValue = totValue + value;
totTax = totTax + tax;
totTotal = totTotal + total;
// display the results of purchase
JOptionPane.showMessageDialog( null, "Amount: " + value +
"\nTax: " + tax + "\nTotal: " + total, "Sale", JOptionPane.INFORMATION_MESSAGE );
// get next code from user
itemCodeString = JOptionPane.showInputDialog("Enter item code:" );
// If sentinel value reached
if ( itemCode == 999 ) {
// display the daily totals
JOptionPane.showMessageDialog( null, "Total amount of items sold today: " + quantity +
"\nValue of ites sold today: " + totValue + "\nTotal tax collected today: " + totTax +
"\nTotal Amount collected today: " + totTotal, "Totals", JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 ); // terminate application
} // end sentinel
} // end message
} // end class SalesRob. -
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) -
hey i'm doing some things, but i need a entry of a binary coded number, i know that an hex number is written like 0xFF but how do i put a binary number in an instruction such as:
byte b
b="binary number"I see what you want to do, but you can only do this with octal and hex. With binary, you would have to do it something like this:
byte b = Byte.parseByte("01101001", 2); // base-2 -
Need help with my numbers app synching with icloud
My numbers app just stopped synching with icloud and my ipad2. And vice versa. I deleted then reinstalled the app, synched the phone, etc. and it still won't transfer to iclous. Any suggestions?
Find your serial number quickly
Sign in, activation, or connection errors | CS5.5 and later, Acrobat DC
Mylenium
Maybe you are looking for
-
How can I create a query with tables in INFOSET?
Dear Gurus, How can I create a query with tables in INFOSET? Just tables and fields INFOSET? Kind Regards,
-
Is it possible to get the table by knowing its name only (string)
public bool IsShowTable get { return _IsShowTable; } set { _IsShowTable = value; if (_IsShowTable) //Type type = Type.GetType(GraphSelected); //Object o = (Activator.CreateInstance(type)); using (var ctx = new PD5500DBEntities()) DataGridSrc = new Ob
-
every time i try to update i get a message saying can't update for this id fought by a different user or item refunded or cancelled
-
If I bought Apple TV could I use mirroring to watch a film online ???
I just want to know if I bought Apple TV would I be able to watch a film online and mirror it on to my tv
-
Get Attachment name with rules/filters
Hello! I want to create a rule through the GroupWise API that trashes incoming mails with certain attachment names. In the CreateRule-Screen there are tons of "filterable" fields avialable, both user defined and system internal, one of them is attach