Re: [ljc] A little Friday morning challenge for the group...

From: Sam B.
Sent on: Friday, January 25, 2013 11:47 AM
Math.random not very efficient. Rather using java.util.Random class.
That would become
new Random().nextInt(max - min +1) + min

But if you don't want to be fooled by randomness there's a nice thread on S.O about this at 

On 25/01/2013, at 12:20 PM, Dan Haywood <[address removed]> wrote:

return (max+1-min) * Math.random() + min


On 25 January[masked]:01, Wesley Hall <[address removed]> wrote:
Hello folks,

I came across what turned out to be a pretty interesting problem on a
project of mine last night, and I thought I would share it with you
guys. I am interested to see if anyone can come up with a better
solution than I did (highly likely I suspect :)).

Your mission, should you choose to accept it, is to write a method, in
Java, with the following signature...

public static long generateRandom(long min, long max) {
   // code here
}

Such that the method generates a random long value that is between the
two parameters provided (inclusive). The only restriction on the
parameters is that max >= min, for brevity you can assume this is
ensured outside of the method and that you don't need to check inside.

The first person to provide a working solution gets to look like a
hero... and if you provide a solution that I think is better than the
one I have, then I will (with your permission), use this version in
the library that I am about to open source and give you contributor
credit.

GO....

Wes




--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
http://www.meetup.com/Londonjavacommunity/
This message was sent by Wesley Hall ([address removed]) from LJC - London Java Community.
To learn more about Wesley Hall, visit his/her member profile: http://www.meetup.com/Londonjavacommunity/members/15396461/
Set my mailing list to email me

As they are sent
http://www.meetup.com/Londonjavacommunity/list_prefs/?pref=1

In one daily email
http://www.meetup.com/Londonjavacommunity/list_prefs/?pref=2

Don't send me mailing list messages
http://www.meetup.com/Londonjavacommunity/list_prefs/?pref=0
Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]






--
Remarque : Si vous cliquez sur « RÉPONDRE », votre message sera envoyé à tous les membres de la liste de diffusion ([address removed])
Ce message a été envoyé par Dan Haywood ([address removed]), du groupe LJC - London Java Community.
Pour en savoir plus sur Dan Haywood, consultez son profil de membre
Régler ma liste de diffusion pour recevoir des e-mails Chaque fois qu'ils sont envoyés | En un seul e-mail quotidien | Ne pas m'envoyer de messages de ma liste de diffusion

Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]

Our Sponsors

  • Our Blog

    Read the latest news from the LJC

  • RecWorks Ltd

    Fixing Tech Recruitment using the Power of Community

  • jClarity

    Java/JVM Performance Analysis Tools & mentoring for Java related matters

  • LJC Aggrity

    Our LJC Aggrity site contains blog posts from our members

  • LJC Book Club

    Our Book club with book reviews from our members

  • Devoxx UK

    Java Community Conference, in collaboration with the LJC 12/13 Jun 14

  • SkillsMatter

    "Host, help organise, promote, film many of our meetings."

  • Packt Publishing

    A publishing company specializing on specific technologies and solutions

  • Java.Net

    We are an official Java User Group recognised by Oracle's JUG program

  • JRebel

    Free 3 month J-Rebel license.

  • O'Reilly

    40% discount on printed books and 50% on e-books.

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy