• Post Reply Bookmark Topic Watch Topic
  • New Topic

Randomizer  RSS feed

 
priyanshi bhardwaj
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am trying to create a randomizer in java.The Goal is the data from the database get's randomized to its different user, for example, you can say it happens in online tests question sequence is in randomized order to different people giving that test.
Any Suggestion is appreciated.Thanks in advance
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Math.random()?
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you specifically want a double in the range 0.0 ≤ x < 1.0, I suggest you avoid Math#random. Use the Random class or one of its subtypes, for reasons explained here and in more detail here.For randomising Lists, I suggest you go through the methods of the Collections class.
 
priyanshi bhardwaj
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
priyanshi bhardwaj wrote: for example, you can say it happens in online tests question sequence is in randomized order to different people giving that test.
specifically for achieving the above goal random class a good option?The solution which you are suggesting is I should fetch my data from the database and pass it through this random class then display it to the user accordingly? 

I am just clarifying this... is there any other option other than this? Thanks
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so, you can either use Math.random() or Random class (better to use this).
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...or, as Campbell mentions, if it's a Collection you want to"shuffle" then there's method that will do that for you.
 
Tim Moores
Saloon Keeper
Posts: 4036
94
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there any other option other than this?

Lots, I should think. But to suggest something else we'd have to know in which way the approaches that have been suggested so far do not meet your requirements.
 
priyanshi bhardwaj
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:
is there any other option other than this?

Lots, I should think. But to suggest something else we'd have to know in which way the approaches that have been suggested so far do not meet your requirements.

I was just asking actually I already knew above-suggested approaches but I just wanted to know bit different way of doing the same thing.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you already know some options, please tell us, to avoid our trying to teach our grandmothers to suck eggs. It is much easier if we know you are looking for ”advanced“ options.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!