I need to create a list of random numbers between two bounds in Excel. The trick is the numbers need to be odd. So I can't just use randbetween()
. Should I just use something like =if(a1 % 2 =0) then a1=a1+1
. I don't know the syntax for that in Excel but what I'm getting at is if the number is even (mod 2 =0) then add one.
相关问题
- Excel sunburst chart: Some labels missing
- Error handling only works once
- Excel formula in VBA code
- Excel VBA run time error 450 from referencing a ra
- DoCmd.TransferSpreadsheet is not recognizing works
相关文章
- Get column data by Column name and sheet name
- programmatically excel cells to be auto fit width
- Unregister a XLL in Excel (VBA)
- How to prevent excel from truncating numbers in a
- numeric up down control in vba
- Declare a Range relative to the Active Cell with V
- What's the easiest way to create an Excel tabl
- How to create a hyperlink to a different Excel she
I know I am in the game late, but wouldn't this be just as simple.
Use a little trick.
CEILING
andFLOOR
have a second parameter which is what you need.You could also use RAND() here to be compatible with earlier excel versions, generically this formula will give you an even distribution, assuming C2 contains the lower bound and D2 the upper (both odd numbers)
=INT(RAND()*((D$2-C$2)/2+1))*2+C$2
You could get a random number n with a different range, and calculate 2*n+1 for your cell value. I presume lower bound is 0 (or 1), so your new range starts off at 0 as well (if not, see how you calculate the upper bound). For the upper bound, if you want m as your largest odd integer, then your upper bound is (obviously)
(m-1)/2
.As an example, say you want odd numbers between 15 and 27. Your lower bound for randbetween will be
(15-1)/2 = 7
, and upper bound will be(27-1)/2 = 13
. So, the cell formula will be=2*randbetween(7, 13)+1
.