## Generate Random Input from an Array according to given Probabilities

Write an algorithm to generate any one of the given N numbers according to given probabilities.

Coding made easy

Write an algorithm to generate any one of the given N numbers according to given probabilities.

In this post, we will discuss how to generate fair results from a biased coin which prefer one side of the coin over another, and returns TAILS with p probability and HEADS with (1-p) probability

In this post, we will discuss division of two numbers (integer or decimal) using Binary Search Algorithm.

Given an binary array of size two having alteast one element as zero, write a single line function to set both its elements to zero. Use of ternary operator and direct assignment of elements are not allowed.

Write an algorithm to generate numbers from 1 to 7 with equal probability using a specified function which produces random numbers between 1 to 5 with equal probability.

In this post, we will see how to implement ternary-like operator in C without using conditional expressions like ternary operator, if–else expression or switch-case statements.

Given a number, find out if it is even or odd without using any conditional statement (if-else) or ternary operator.

In this post, we will discuss how to determine if two integers are equal without using comparison operators (==, !=, < , >, < =, >=) & arithmetic operators (+, -, *, /, %).

Write an algorithm to generate random numbers from 1 to 12 with equal probability using a given function which generates random numbers from 1 to 6 with equal probability.

Given two integers, swap them in single line in Java. There are many expressions to swap two variables in single line in Java. Notice that all below methods can also be used with C/C++. 1. Using Bitwise XOR(^) Operator

1 2 3 4 5 6 7 8 9 10 11 |
class Swap { public static void main (String[] args) { int x = 5, y = 10; x = x ^ y ^ (y = x); System.out.println("Values of x and y after swapping are " + x + " and " + y); } } |

Download Run Code 2. Using Addition and Subtraction Operator …

Write an algorithm to generate 0, 1 and 2 with equal probability using a specified function which either produces 0 or 1 with 50% probability each.

Write an algorithm to get 0 and 1 with equal probability using a function which generates random numbers from 1 to 5 with equal probability.