From owner-svn-src-all@freebsd.org Sat May 21 22:02:12 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 91375B44C3C; Sat, 21 May 2016 22:02:12 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-ig0-f179.google.com (mail-ig0-f179.google.com [209.85.213.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 656521FCD; Sat, 21 May 2016 22:02:12 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-ig0-f179.google.com with SMTP id fh2so7935141igd.1; Sat, 21 May 2016 15:02:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :date:message-id:subject:from:to:cc:content-transfer-encoding; bh=d34pICmjj+pJXNgefPcHZ6LJ7QW64lec4T3A/La27qQ=; b=LZHAkIDBrL4ysUBp7OZesdg9uQf9xPsW2ruSJJMJslMcJQf0ENLmp9VdSVGtmS7RWR y7hV41NM9GSrDDraePnsvYCRZ0DAf+GEcZR4KxSP/0PpPSqFBayQcbM+Z6p48igsyy3y MC/6IqSYNawCbx6YD3qc7O/D2uo/ME2XCIE5BpZmqF8CApwCoqw9F9VX9cnkZ+rppBEa nE+uxYwgkukYBO+lzBDOl0dX4Z06h/HpydrktnaQDTfl1SVQVFlq5BBPB0F1sjiAqxcz OLKKuFUzIuF/9+7dva0GqOd35u/P7dPFjWiRDpLsDpSCfwGIv7T7gHqSYbQ9RN9o+jnl ob9A== X-Gm-Message-State: AOPr4FVJUbEOnNcDk14C7V2jWTdBqxFn5LnfkYZAxaQWefCSyGuS0bT0KHuy8P7P34peeg== X-Received: by 10.50.8.2 with SMTP id n2mr7712341iga.39.1463867718138; Sat, 21 May 2016 14:55:18 -0700 (PDT) Received: from mail-io0-f173.google.com (mail-io0-f173.google.com. [209.85.223.173]) by smtp.gmail.com with ESMTPSA id 11sm7827250ioe.25.2016.05.21.14.55.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 May 2016 14:55:18 -0700 (PDT) Received: by mail-io0-f173.google.com with SMTP id p64so80673884ioi.2; Sat, 21 May 2016 14:55:17 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.107.38.79 with SMTP id m76mr8777230iom.7.1463867717430; Sat, 21 May 2016 14:55:17 -0700 (PDT) Reply-To: cem@FreeBSD.org Received: by 10.36.205.70 with HTTP; Sat, 21 May 2016 14:55:17 -0700 (PDT) In-Reply-To: References: <201605211752.u4LHqiHQ031457@repo.freebsd.org> Date: Sat, 21 May 2016 14:55:17 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r300377 - head/sys/compat/ndis From: Conrad Meyer To: Pedro Giffuni Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 May 2016 22:02:12 -0000 On Sat, May 21, 2016 at 1:40 PM, Pedro Giffuni wrote: > > > On 05/21/16 14:05, Conrad Meyer wrote: >> Won't this still return a negative integer in many cases? >> >> random(9) returns u_long, whereas this rand() routine returns 'int'. >> >> Even on architectures where long is the same size as ordinary >> integers, the range of possible results of the 'random() / 2 + 1' >> expression, before implicit cast to signed, is [1, 2^31] (inclusive). > > > According to: > sys/libkern/random.c > > The result is uniform on [0, 2^31 - 1]. Ah, I missed that. Sorry! In that case, I'm not sure why this is needed =E2=80=94 the result fits in a non-negative 2's complement signed integer. >> 2^31 is not representable by typical signed 32-bit integers, so this >> will wrap to INT_MIN. Also, I'm not sure why zero is excluded from >> the range. >> > > It is not a good reason but the zero is sometimes inconvenient: if > the value is going to be used as a multiplier in some calculation > it will basically kill the random component. Sure, but anyone using a random number as a multiplier must consider the range of the random function. They should handle rand() =3D=3D 0 (perhaps by this '/ 2 + 1' construct). I don't think that is the responsibility of a rand() function. Best, Conrad