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
146
votes
5 answers

Difference between '..' (double-dot) and '...' (triple-dot) in range generation?

I've just started learning Ruby and Ruby on Rails and came across validation code that uses ranges: validates_inclusion_of :age, :in => 21..99 validates_exclusion_of :age, :in => 0...21, :message => "Sorry, you must be over 21" At first I thought…
juil
  • 2,408
  • 3
  • 18
  • 18
145
votes
10 answers

Determining if a variable is within range?

I need to write a loop that does something like: if i (1..10) do thing 1 elsif i (11..20) do thing 2 elsif i (21..30) do thing 3 etc... But so far have gone down the wrong paths in terms of syntax.
btw
  • 7,006
  • 9
  • 40
  • 40
144
votes
19 answers

Select data from date range between two dates

I have a table Named Product_Sales and it holds data like this Product_ID Sold_by Qty From_date To_date 3 12 7 2013-01-05 2013-01-07 6 22 14 2013-01-06 2013-01-10 8 11 9 2013-02-05 2013-02-11 Now what is the query if I want to select…
Ronjon
  • 1,789
  • 4
  • 16
  • 26
133
votes
18 answers

How does one make random number between range for arc4random_uniform()?

so my goal in this codebit is to randomly roll two dice and as we all know your regular die only has 6 sides so I imported Foundation for access to arc4random_uniform(UInt32). I attempted using the range of (1..7) to avoid randomly getting 0 however…
arcreigh
  • 1,423
  • 2
  • 11
  • 12
128
votes
10 answers

How to create range in Swift?

In Objective-c we create range by using NSRange NSRange range; So how to create range in Swift?
vichhai
  • 2,548
  • 2
  • 15
  • 25
124
votes
5 answers

In Kotlin can I create a range that counts backwards?

I looked at the documentation for the Ranges and I see no mention of backwards ranges. Is it possible to do something like: for (n in 100..1) { println(n) } And get results: 100 99 98 ...
jjnguy
  • 136,852
  • 53
  • 295
  • 323
123
votes
13 answers

Is there a reason that we cannot iterate on "reverse Range" in ruby?

I tried to iterate backwards with using a Range and each: (4..0).each do |i| puts i end ==> 4..0 Iteration through 0..4 writes the numbers. On the other Range r = 4..0 seems to be ok, r.first == 4, r.last == 0. It seems to be strange to me that…
fifigyuri
  • 5,771
  • 8
  • 30
  • 50
114
votes
15 answers

Is there a need for range(len(a))?

One frequently finds expressions of this type in python questions on SO. Either for just accessing all items of the iterable for i in range(len(a)): print(a[i]) Which is just a clumbersome way of writing: for e in a: print(e) Or for…
Hyperboreus
  • 31,997
  • 9
  • 47
  • 87
113
votes
8 answers

Is there a range class in C++11 for use with range based for loops?

I found myself writing this just a bit ago: template class range_class { public: class iterator { friend class range_class; public: long int operator *() const { return i_; } const…
Omnifarious
  • 54,333
  • 19
  • 131
  • 194
108
votes
3 answers

Pandas: create new column in df with random integers from range

I have a pandas data frame with 50k rows. I'm trying to add a new column that is a randomly generated integer from 1 to 5. If I want 50k random numbers I'd use: df1['randNumCol'] = random.sample(xrange(50000), len(df1)) but for this I'm not sure…
screechOwl
  • 27,310
  • 61
  • 158
  • 267
103
votes
4 answers

JavaScript Array: get "range" of items

Is there an equivalent for ruby's array[n..m] in JavaScript? For example: >> a = ['a','b','c','d','e','f','g'] >> a[0..2] => ['a','b','c']
shdev
  • 1,855
  • 4
  • 17
  • 18
102
votes
16 answers

How to check if an integer is within a range of numbers in PHP?

How can I check if a given number is within a range of numbers?
Richard Peers
  • 1,131
  • 3
  • 9
  • 7
100
votes
16 answers

range over character in python

Is there an way to range over characters? something like this. for c in xrange( 'a', 'z' ): print c I hope you guys can help.
huan
  • 1,121
  • 2
  • 8
  • 6
97
votes
1 answer

Sample http range request session

Is it possible to show me a sample http session with range requests. I mean what would be the request and response headers?
chamal
  • 1,103
  • 1
  • 8
  • 6
97
votes
12 answers

Strange result when removing item from a list while iterating over it in Python

I've got this piece of code: numbers = list(range(1, 50)) for i in numbers: if i < 20: numbers.remove(i) print(numbers) But, the result I'm getting is: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,…
Finger twist
  • 3,546
  • 9
  • 42
  • 52