Probability based logic writing The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Word for: a synonym with a positive connotation?
Hello, Goodbye, Adios, Aloha
What other Star Trek series did the main TNG cast show up in?
How to substitute curly brackets with round brackets in a grid of list
Nested ellipses in tikzpicture: Chomsky hierarchy
Would an alien lifeform be able to achieve space travel if lacking in vision?
Using dividends to reduce short term capital gains?
Solving overdetermined system by QR decomposition
How to determine omitted units in a publication
Ubuntu Err :18 http://dl.google.com/linux/chrome/deb stable Release.gpg KEYEXPIRED 1555048520
Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?
Do working physicists consider Newtonian mechanics to be "falsified"?
Is an up-to-date browser secure on an out-of-date OS?
What aspect of planet earth must be changed to prevent the industrial revolution?
Working through Single Responsibility Principle in Python when Calls are Expensive
Why are Marketing Cloud timestamps not stored in the same timezone as Sales Cloud?
Drawing vertical/oblique lines in Metrical tree (tikz-qtree, tipa)
Deal with toxic manager when you can't quit
Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?
Simulating Exploding Dice
Why did Peik Lin say, "I'm not an animal"?
How to make Illustrator type tool selection automatically adapt with text length
Word to describe a time interval
What do I do when my TA workload is more than expected?
Probability based logic writing
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
In a bucket, there are total 100 balls, in which 10 are red, 40 are green and remaining 50 are black. Every ball has a numeric unique tag starting from 1 to 100, like red balls have tag 1 to 10 than green balls have their tags from 11 to 50 and rest black tags are from 51 to 100.
Now If I take a random number between 1 and 100, lets say 55, it will be a black ball. So to get the correct type/color of ball, I have written a logic below
// lets assume r is random number
// rb is total count of red balls
// gb is total count of green balls
// bb is total count of black balls
if(r <= rb)
// its a red ball
else if(r <= rb + gb)
// its a green ball
else if(r <= rb + gb + bb)
// its a black ball
this seem to be correct to me, is this looks like a patch code or can we make it is a single liner code somehow?
java
New contributor
Ashok Damani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
In a bucket, there are total 100 balls, in which 10 are red, 40 are green and remaining 50 are black. Every ball has a numeric unique tag starting from 1 to 100, like red balls have tag 1 to 10 than green balls have their tags from 11 to 50 and rest black tags are from 51 to 100.
Now If I take a random number between 1 and 100, lets say 55, it will be a black ball. So to get the correct type/color of ball, I have written a logic below
// lets assume r is random number
// rb is total count of red balls
// gb is total count of green balls
// bb is total count of black balls
if(r <= rb)
// its a red ball
else if(r <= rb + gb)
// its a green ball
else if(r <= rb + gb + bb)
// its a black ball
this seem to be correct to me, is this looks like a patch code or can we make it is a single liner code somehow?
java
New contributor
Ashok Damani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
In a bucket, there are total 100 balls, in which 10 are red, 40 are green and remaining 50 are black. Every ball has a numeric unique tag starting from 1 to 100, like red balls have tag 1 to 10 than green balls have their tags from 11 to 50 and rest black tags are from 51 to 100.
Now If I take a random number between 1 and 100, lets say 55, it will be a black ball. So to get the correct type/color of ball, I have written a logic below
// lets assume r is random number
// rb is total count of red balls
// gb is total count of green balls
// bb is total count of black balls
if(r <= rb)
// its a red ball
else if(r <= rb + gb)
// its a green ball
else if(r <= rb + gb + bb)
// its a black ball
this seem to be correct to me, is this looks like a patch code or can we make it is a single liner code somehow?
java
New contributor
Ashok Damani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
In a bucket, there are total 100 balls, in which 10 are red, 40 are green and remaining 50 are black. Every ball has a numeric unique tag starting from 1 to 100, like red balls have tag 1 to 10 than green balls have their tags from 11 to 50 and rest black tags are from 51 to 100.
Now If I take a random number between 1 and 100, lets say 55, it will be a black ball. So to get the correct type/color of ball, I have written a logic below
// lets assume r is random number
// rb is total count of red balls
// gb is total count of green balls
// bb is total count of black balls
if(r <= rb)
// its a red ball
else if(r <= rb + gb)
// its a green ball
else if(r <= rb + gb + bb)
// its a black ball
this seem to be correct to me, is this looks like a patch code or can we make it is a single liner code somehow?
java
java
New contributor
Ashok Damani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ashok Damani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ashok Damani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 3 mins ago
Ashok DamaniAshok Damani
1011
1011
New contributor
Ashok Damani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ashok Damani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Ashok Damani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Ashok Damani is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217346%2fprobability-based-logic-writing%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Ashok Damani is a new contributor. Be nice, and check out our Code of Conduct.
Ashok Damani is a new contributor. Be nice, and check out our Code of Conduct.
Ashok Damani is a new contributor. Be nice, and check out our Code of Conduct.
Ashok Damani is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217346%2fprobability-based-logic-writing%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown