Tagged Questions
7
votes
4answers
683 views
Read from a file and pick a random line
I've been learning Java lately and had some great feedback from the previous threads (hangman and guess a number games).
I was challenged by a user to try to get this code done, so I'm posting it here ...
14
votes
5answers
3k views
1
vote
1answer
171 views
Reservoir sampling
Reservoir sampling implementation. Reservoir sampling is a family of randomized algorithms for randomly choosing a sample of k items from a list S containing n items, where n is either a very large or ...
4
votes
3answers
122 views
Weighted probabilistic sampling
Problem description.
Returns strings with probability determined by the frequency
of each of the strings.
eg: if "foo" has weight of 50% and "bar" has weight of another 50% then both foo and
bar ...
19
votes
6answers
5k views
Guessing a unique 4 random digits number
I've created a simple game, in which the user needs to guess 4 digits number between 0-9, generated randomly using Random() Each of the 4 digits are different from ...
21
votes
10answers
5k views
Generating Even Random Numbers
I have this class which is used as part of a game. It needs to generate Random Even values, which is done by generating random numbers until the result is even.
Is there a better way to do this?
...
5
votes
2answers
523 views
Generating random numbers
I'm trying to refactor the following code and could use some suggestions. Basically, three functions generating random numbers in different ways are called:
...
9
votes
2answers
515 views
Guess a random number between a selected interval
My project for my class is to create a Java-based game where the user must enter a number between 1-20 and a number between 250 and 300. The computer randomly chooses a number between those 2 numbers. ...
12
votes
5answers
692 views
Optimize random number generator
I have a method that generates a 10 digit random number where each digit occurs only once.
eg:
0123456789
3645720918
Is there any way this method could be ...
4
votes
4answers
2k views
Random walk on a 2D grid
The program assignment:
A drunkard in a grid of streets randomly picks one of four directions
and stumbles to the next intersection, then again randomly picks one
of four directions, and so ...
4
votes
2answers
3k views
Random password generator
I just wrote my first Java class, and I wanted to share it with you and maybe get some quick check from more experiences coders than I am.
I want to learn OOP, and Java is just the tool I thought was ...
2
votes
2answers
161 views
Shuffling algorithm suitable?
Just checking that this shuffling algorithm is suitable. Or maybe there could be improvements?
...
1
vote
1answer
198 views
Simulating the radioactive decay of atoms using a random number generator
I've found two ways of writing the same program (one that only uses local variables, but no methods other than the main one) and other that uses one instance variable that is used in two methods.
...
1
vote
4answers
177 views
Can you review my random number wrapper class
I made this class to handle any min max integer value and return a random number in the entered parameter range. I tested it to work with all combinations(I think). But is this totally wrong or ...
2
votes
1answer
286 views
Discrete random variable generator
There is my SSCCE to generate a value of discrete random variable.
values is set of value the RV can take and procents is ...
4
votes
3answers
656 views
Extending java.util.Random.nextInt(int) into nextLong(long)
In java.util.Random the Oracle implementation of nextInt(int) is as follows:
...
7
votes
2answers
238 views
Tidy up number counting code
I am hoping someone can help me tidy up my code (for a practical for university). The practical is to use the random number generator to produce 100 integers (all between 1 and 10) and store them in ...
10
votes
4answers
643 views
Turning an array of words into a random license plate
This is an assignment question from school:
Write a method called licencePlate that takes an array of objectionable words and returns a random licence plate ...
10
votes
3answers
384 views
Is this code an efficient implementation of Reservoir Sampling?
I posted this an answer this to a question about drawing a random line from a file too large to put into memory. I hacked the below code together. In essence, this is what Reservoir Sampling does, in ...
6
votes
3answers
403 views
Imitate randomness of a dice roll
I have written some code in Java that consists of two classes. I have tried my best and I want you to tell me if I can improve and how good this is.
Also, how important is OOP? Java is an object ...
4
votes
7answers
691 views
Reduce repetitive code in Lotto simulator
I'm extremely new to Java, and I had a bit of an attempt at making something that you could call lotto. I've still got a lot more to go on it, but things are becoming tedious, and I am sure there is a ...
7
votes
1answer
182 views
Random Q&A system
Basically, I made a simple app for my Android, where it picks a random question for you, and picks specific answers. Only 1 of the answers is correct, while other's aren't.
Also, after editing the ...
8
votes
1answer
6k views
OAuth Provider token generation
I'm currently creating an OAuth provider in Java using Jersey. To the best of my knowledge Jersey does not provide a method to create oauth tokens so I'm creating my own.
For those unfamiliar with ...