addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcredit-cardcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobe--smallglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1languagelaunch-new-window--smalllight-bulblinklocation-pinlockm-swarmSearchmailmediummessagesminusmobilemoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahooyoutube

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

From: Neil B.
Sent on: Friday, January 25, 2013 11:47 AM



On Fri, Jan 25, 2013 at 11:43 AM, Wesley Hall <[address removed]> wrote:
Haha Anup, I actually had a feeling somebody would reference that Dilbert cartoon. I will bestow upon you 'hero' status for being a Dilbert fan, but atlas I cannot use this version.

I will have to add to the requirements (which I probably should not have left implicit), that there must be at least a chance that any number in the range provided could be generated.

Oookay, picky, but here you go:

    private static long previous = Long.MIN_VALUE;

    public static long generateRandom(long min, long max) {
        if (previous < min || previous > max) previous = min;
        return previous ++;
    }

 


On Fri, Jan 25, 2013 at 11:27 AM, Anup <[address removed]> wrote:
public static long generateRandom(long min, long max) {
   // 
http://dilbert.com/strips/comic/2001-10-25/
   return 9;
}


On Friday, January 25, 2013, Wesley Hall 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]



--
Anup






--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Anup ([address removed]) from LJC - London Java Community.
To learn more about Anup, visit his/her member profile





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
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
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

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

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