Questions tagged [range]

A range is an extent of values between its lower and upper bound. It can refer to a DOM Range, the Ruby Range class, the Python range function, Perl 5's `..` operator, Perl 6's Range Class, or PostgreSQL's range types.

A range is an extent of values between its lower and upper bound. Examples include a DOM Range, the Ruby Range class, the Python range function, Perl 5's .. operator (in list context), Perl 6's Range Class and PostgreSQL's range types.

In statistics, range is the size of the smallest interval which contains all the data and provides an indication of statistical dispersion. It is measured in the same units as the data. Since it only depends on two of the observations, it is most useful in representing the dispersion of small data sets.

10562 questions
269
votes
8 answers

How to scale down a range of numbers with a known min and max value

So I am trying to figure out how to take a range of numbers and scale the values down to fit a range. The reason for wanting to do this is that I am trying to draw ellipses in a java swing jpanel. I want the height and width of each ellipse to be…
user650271
  • 2,853
  • 3
  • 17
  • 8
255
votes
9 answers

Python 3 turn range to a list

I'm trying to make a list with numbers 1-1000 in it. Obviously this would be annoying to write/read, so I'm attempting to make a list with a range in it. In Python 2 it seems that: some_list = range(1,1000) would have worked, but in Python 3 the…
Boathouse
  • 2,665
  • 2
  • 14
  • 6
234
votes
15 answers

Is it possible to make a `for` loop without an iterator variable? (How can I make make code loop a set number of times?)

Is it possible to do following without the i? for i in range(some_number): # do something If you just want to do something N amount of times and don't need the iterator.
James McMahon
  • 48,506
  • 64
  • 207
  • 283
213
votes
6 answers

Can I use the range operator with if statement in Swift?

Is it possible to use the range operator ... and ..< with if statement. Maye something like this: let statusCode = 204 if statusCode in 200 ..< 299 { NSLog("Success") }
Jimmy
  • 10,427
  • 18
  • 67
  • 122
212
votes
24 answers

range() for floats

Is there a range() equivalent for floats in Python? >>> range(0.5,5,1.5) [0, 1, 2, 3, 4] >>> range(0.5,5,0.5) Traceback (most recent call last): File "", line 1, in range(0.5,5,0.5) ValueError: range() step argument must…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
208
votes
8 answers

How to generate a random number between a and b in Ruby?

To generate a random number between 3 and 10, for example, I use: rand(8) + 3 Is there a nicer way to do this (something like rand(3, 10)) ?
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
204
votes
6 answers

How to produce a range with step n in bash? (generate a sequence of numbers with increments)

The way to iterate over a range in bash is for i in {0..10}; do echo $i; done What would be the syntax for iterating over the sequence with a step? Say, I would like to get only even number in the above example.
SilentGhost
  • 307,395
  • 66
  • 306
  • 293
193
votes
4 answers

Revert a range of commits in git

How can I revert a range of commits in git? From looking at the gitrevisions documentation, I cannot see how to specify the range I need. For example: A -> B -> C -> D -> E -> HEAD I want to do the equivalent of: git revert B-D where the result…
Alex Spurling
  • 54,094
  • 23
  • 70
  • 76
189
votes
14 answers

HTML5 input type range show range value

I am making a website where I want to use range slider(I know it only supports webkit browsers). I have integrated it fully and works fine. But I would like to use a textbox to show the current slide value. I mean if initially the slider is at value…
Niraj Chauhan
  • 7,677
  • 12
  • 46
  • 78
183
votes
4 answers

Can I hint the optimizer by giving the range of an integer?

I am using an int type to store a value. By the semantics of the program, the value always varies in a very small range (0 - 36), and int (not a char) is used only because of the CPU efficiency. It seems like many special arithmetical optimizations…
rolevax
  • 1,670
  • 1
  • 14
  • 21
171
votes
6 answers

Generate random numbers using C++11 random library

As the title suggests, I am trying to figure out a way of generating random numbers using the new C++11 library. I have tried it with this code: std::default_random_engine generator; std::uniform_real_distribution
smac89
  • 39,374
  • 15
  • 132
  • 179
159
votes
18 answers

Python: how to print range a-z?

1. Print a-n: a b c d e f g h i j k l m n 2. Every second in a-n: a c e g i k m 3. Append a-n to index of urls{hello.com/, hej.com/, ..., hallo.com/}: hello.com/a hej.com/b ... hallo.com/n
hhh
  • 50,788
  • 62
  • 179
  • 282
158
votes
12 answers

Create a list from 0 to N

How can I create easily a range of consecutive integers in dart? For example: // throws a syntax error :) var list = [1..10];
Cequiel
  • 3,505
  • 6
  • 27
  • 44
158
votes
17 answers

Java: random long number in 0 <= x < n range

Random class has a method to generate random int in a given range. For example: Random r = new Random(); int x = r.nextInt(100); This would generate an int number more or equal to 0 and less than 100. I'd like to do exactly the same with long…
Vilius Normantas
  • 3,708
  • 6
  • 25
  • 38
157
votes
8 answers

swift convert Range to [Int]

how to convert Range to Array I tried: let min = 50 let max = 100 let intArray:[Int] = (min...max) get error Range is not convertible to [Int] I also tried: let intArray:[Int] = [min...max] and let intArray:[Int] = (min...max) as [Int] they…
haitham
  • 3,398
  • 6
  • 21
  • 35