Increasing Probability for generating specific random numbers [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to generate random numbers . Now, I want to generate a new set of random numbers in a way that that increases the probability of returning the numbers that were generated earlier.What is the best way of achieving this ?

I dont know if predefined functions exist or not, but I have something in mind that you can try.
Make an ArrayList of the numbers. (eg. if you want to generate from
0to30, then make an ArrayList of Integers from 0 to 30).
Shuffle the ArrayList(Collections.shuffle())
Pick the first 2 numbers.
Then, just add those 2 numbers into the ArrayList as many times as you want the probablity to shift towards them.
Shuffle again and pick

You can store that values on array.
And you can have a random condition also for having a new pair of number or pick randomly on your array.

Related

What can be the algorithm to find the max number that appear the most in an array? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm trying to find out an algorithm that returns the number that has more occurrences in an array that contains number from 0 to 9 and that has a complexity of n.
I though to using an HashMap but it would require n^2
If anyone can write the code down,i'd prefer in Java but pseudocode is the same
Use ten counters (one per digit), scan the array and increment the counters corresponding to the digits. (You are actually computing the histogram of the digit frequencies.)
Report the digit with the largest counter.

get subset of elements from set in circular way [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Consider a set with like 100 elements.
Set<String> originalSet; //[1....100] size is 100
From originalSet, (m) subset of elements of some size(n) with some starting index(i) have to retrieved.
Example:
m = 4, n = 45, i = 1
Following have to be retrieved
subset1[1-45], subset2[46-90], subset3[91-35], subset4[36-80]
Whats the best way of doing this.
First of all, Set is unordered so it does not make sense to talk about indices etc. List would make more sense here.
Next, you have to be explicit about what you mean by "best". Performance on insertion? Random access? Creation of your n-from-i subset? These are important question to choose the implementation.
I think two primary options would be linked list with special handling of the last element in subList operation or an array-based list.
Assuming your set has some notion of order, you could write this with
Iterable<Iterable<String>> slices =
Iterables.limit(
Iterables.partition(
Iterables.skip(
Iterables‌​.cycle(originalSet),
i),
n),
m);
If you wanted a set out of this, you'd have to do a transform or something; if you have Java 8 that'd just be something like Iterables.transform(..., ImmutableSet::copyOf).

How to randomly select one from two integers? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So lets say I want to randomly choose from the set of two numbers 1 and 3.
How do I go about doing that? Do I just assign int a to 1, int b to 3, and then do randomly select from a and b?
If there are only two numbers to choose from then you can use the value of a boolean, because it returns either true or false.
One-liner solution assuming that int a = 1 and int b = 3:
int randomOfTwoInts = new Random().nextBoolean() ? a : b;
If you have a specific list of numbers then put them in list structure (an array works well). Then you have the easier task of looking for a random index in the range from 0 to last array index. This post lists strategies for doing that:How do I generate random integers within a specific range in Java?

Take a result of two long numbers using an array in Java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want to take a sum, quotient, remainder of two numbers using an array in java.
123456789012345+7654321, 123456789012345/7654321. What is a simplest way to calculate it using Java?(I am new to Java.)
Since you are new to java I recommend reading up on some tutorials. As it seems you are not familiar with java in general. An example, which I have not used myself, is http://www.javaworld.com/blog/java-101. It may be worth your time to read this over.
As for your actual question, you would create a variable in java. Then assign your first number to this variable. After doing this, you can perform some operations on the number.
An example in sudo code to give you an idea while not doing the work for you.
void method
var number = 100
number = number + 200
number = number / 20
print("result" . number)
If you plan to use an array its the same process in a loop.
http://www.tutorialspoint.com/java/java_loop_control.htm

How to print arrays index/subscript [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Few Java questions:
How to prompt user for input?
How to save input from user in an array?
How to average numbers in an array?
How to compare numbers?
How to print information back to the user?
The scenario is as follows: let the user to input 10 numbers into an array. Then loop through the array and average it. Then loop through the array again and compare each value against the average and print the number (and/or loop index) if it is lower than the average of the 10 numbers user entered.
Read the array.
Calculate the average.
Loop through the array
check if it has value less than average
if yes print the index
if no check for the next

Categories

Resources