Random()

Put your problem here if it does not fit any of the other categories.

Random()

Postby ef em el » Thu Mar 10, 2011 6:15 pm

I realize this is more java related than Android but this is the only forum I'm on. :) my trivia app has about 700 questions but I get an incredible amount of repeats due to random new random int w/e next int of the random. Could anybody help me make it more random?
ef em el
Junior Developer
Junior Developer
 
Posts: 18
Joined: Wed Dec 22, 2010 9:16 am

Top

Re: Random()

Postby raj_J2ME » Fri Mar 11, 2011 6:48 am

I think you have to generate the Random number which is unique also, so that there is no repeatability of the question at that generated index.
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: Random()

Postby blundell » Fri Mar 11, 2011 12:24 pm

Whats your code for making it random?
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Random()

Postby ef em el » Fri Mar 11, 2011 7:27 pm

Thanks for the response.

Random randNum = new Random();
int numUsed = randNum.nextInt(333);
ef em el
Junior Developer
Junior Developer
 
Posts: 18
Joined: Wed Dec 22, 2010 9:16 am

Re: Random()

Postby blundell » Fri Mar 11, 2011 11:42 pm

So you have 700 responses but you only ask for a random number between 0-333.

Your code is as random as it's gonna get. You could save the last selected number and if the next number == that number then random() again, but saying that then it wouldn't be truly random!!
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 16 guests