473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Quick question on probabilty with java

72
Just a quick question on generating probability with java,

lets say i got a probability of 0.2 or 20% before something happens.

can I write it out as

Expand|Select|Wrap|Line Numbers
  1. for(int i = 0; i < size; i++)
  2. {   
  3.    double e = Math.random();
  4.  
  5.    if(e > 0.20)
  6.    {
  7.       //do nothing
  8.    }
  9.    else
  10.    {
  11.       //do something
  12.    }
  13. }
Aug 10 '07 #1
1 1133
JosAH
11,448 Expert 8TB
Just a quick question on generating probability with java,

lets say i got a probability of 0.2 or 20% before something happens.

can I write it out as

Expand|Select|Wrap|Line Numbers
  1. for(int i = 0; i < size; i++)
  2. {   
  3.    double e = Math.random();
  4.  
  5.    if(e > 0.20)
  6.    {
  7.       //do nothing
  8.    }
  9.    else
  10.    {
  11.       //do something
  12.    }
  13. }
Yep, that's fine. The Math.random() pseudo random number generator generates
uniformly distributed numbers in the interval [0,1). Also have a look at the
Random class; it can do a bit more; maybe you need it.

kind regards,

Jos
Aug 10 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Chris Thomasson | last post by:
<wkaras@yahoo.comwrote in message news:1156863246.290976.191710@i3g2000cwc.googlegroups.com... volatile has nothing to do with the memory model... Well, except in Microsoft... ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.