Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33972

Re: Random permutations [was Re: Libraries for sysadmins?]

From Brixomatic <brixomatic@yahoo.com>
Newsgroups comp.lang.java.programmer
Subject Re: Random permutations [was Re: Libraries for sysadmins?]
Date 2016-03-15 19:22 +0100
Organization Aioe.org NNTP Server
Message-ID <MPG.31527135b2b063559896ae@news.aioe.org> (permalink)
References (5 earlier) <nbd7c3$3jp$1@news.albasani.net> <djvt76Fs5qfU2@mid.individual.net> <nbeunm$drn$1@news.albasani.net> <MPG.314541d29a607e059896ad@news.aioe.org> <slrnndmahv.456.avl@login.logic.tuwien.ac.at>

Show all headers | View raw


In article <slrnndmahv.456.avl@login.logic.tuwien.ac.at>, Andreas 
Leitgeb (avl@logic.at) says...
> 
> Brixomatic <brixomatic@yahoo.com> wrote:
> >  int nextInt(int origin, int bound) {
> >    int n = bound - origin;
> >    if (n > 0) {
> >      return nextInt(n) + origin;
> >    }
> >    else {  // range not representable as int
> > The else case should come as a surprise for a lot of people.
> 
> Why? that's just to account for ranges whose length is greater
> than Integer.MAX_VALUE, e.g.:  nextInt(-1, Integer.MAX_VALUE)
> 
> They probably could have used "long"s as fallback, tough.

Sure it's apparent when you see the if-statement, so is the handling of 
an overflow in a proper implementation of a binary search.
But how many people you'd ask to implement such a function, would you 
guess, would not think abut the overflow and be surprised of a wrong 
result? I'd guess about half of them would be caught off guard.

Kind regards,
Wanja

-- 
..Alesi's problem was that the back of the car was jumping up and down 
dangerously - and I can assure you from having been teammate to 
Jean Alesi and knowing what kind of cars that he can pull up with, 
when Jean Alesi says that a car is dangerous - it is. [Jonathan Palmer]

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Libraries for sysadmins? Elena <egarrulo@gmail.com> - 2016-03-04 03:33 -0800
  Re: Libraries for sysadmins? Martin Gregorie <martin@address-in-sig.invalid> - 2016-03-04 11:44 +0000
    Re: Libraries for sysadmins? egarrulo <egarrulo@gmail.com> - 2016-03-04 12:56 +0100
  Re: Libraries for sysadmins? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-03-04 07:43 -0500
  Re: Libraries for sysadmins? Robert Klemme <shortcutter@googlemail.com> - 2016-03-04 18:06 +0100
    Re: Libraries for sysadmins? egarrulo <egarrulo@gmail.com> - 2016-03-04 20:30 +0100
      Random permutations [was Re: Libraries for sysadmins?] Sebastian <news@seyweiler.dyndns.org> - 2016-03-05 00:56 +0100
        Re: Random permutations [was Re: Libraries for sysadmins?] Robert Klemme <shortcutter@googlemail.com> - 2016-03-05 12:11 +0100
          Re: Random permutations [was Re: Libraries for sysadmins?] Sebastian <news@seyweiler.dyndns.org> - 2016-03-05 16:41 +0100
            Re: Random permutations [was Re: Libraries for sysadmins?] Brixomatic <brixomatic@yahoo.com> - 2016-03-05 19:20 +0100
              Re: Random permutations [was Re: Libraries for sysadmins?] Andreas Leitgeb <avl@logic.at> - 2016-03-05 18:46 +0000
                Re: Random permutations [was Re: Libraries for sysadmins?] Brixomatic <brixomatic@yahoo.com> - 2016-03-15 19:22 +0100
                Re: Random permutations [was Re: Libraries for sysadmins?] Andreas Leitgeb <avl@logic.at> - 2016-03-15 22:30 +0000
            Re: Random permutations [was Re: Libraries for sysadmins?] Andreas Leitgeb <avl@logic.at> - 2016-03-05 18:30 +0000
              Re: Random permutations [was Re: Libraries for sysadmins?] Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-03-05 13:46 -0500
                Re: Random permutations [was Re: Libraries for sysadmins?] Andreas Leitgeb <avl@logic.at> - 2016-03-05 19:40 +0000
      Re: Libraries for sysadmins? Robert Klemme <shortcutter@googlemail.com> - 2016-03-05 12:10 +0100
    Re: Libraries for sysadmins? Arne Vajhøj <arne@vajhoej.dk> - 2016-03-04 21:42 -0500
  Re: Libraries for sysadmins? Arne Vajhøj <arne@vajhoej.dk> - 2016-03-04 21:48 -0500

csiph-web