๐บ n Fractions of Int
Split an integer into N evenly-spaced indices, four different ways
- fractions
When you have 100 frames and want to sample 5 evenly-spaced ones, you could compute 0, 25, 50, 75, 100 by hand. Or you could let a node do it. Nilor n Fractions of Int takes a numerator (your total, default 10), a denominator (how many fractions to produce, default 2), and a type that controls exactly where the split points land, then returns that many integers. It's a small arithmetic node, but it's the backbone of "sample evenly across a batch" workflows.
The four modes
starts- the start of each fraction:i * numerator // denominator. For 10/2:[0, 5]. For 10/4:[0, 2, 5, 7](integer division rounds down).ends- the end of each fraction:(i+1) * numerator // denominator. For 10/2:[5, 10].centres- the midpoint of each fraction, computed as(i*numerator + numerator//2) // denominator. For 10/2:[2, 7]. Note the//2is applied before division, so the "centres" are only approximately centered on odd totals - a mild quirk, not a bug.start + end- every fraction's start and the final end, i.e.i * numerator // (denominator - 1). For 10/2:[0, 10]. For 10/3:[0, 5, 10]. This is the "N evenly spaced points including both ends" mode.
Output is fractions, always a list (marked OUTPUT_IS_LIST), with exactly denominator entries.
Where it fits
This is a sampling node for batch pipelines. You have numerator frames/images and want to grab denominator of them spread across the range - feed the resulting list into ๐บ Select Index From List or ๐บ Load Image By Index (whose seed input doubles as an index) to actually pick them. The start + end mode is the classic keyframe sampler: N evenly spaced frames including both endpoints, which is exactly what you want for previews, contact sheets, or extracting a storyboard from a video. starts/ends/centres are the variants you'd want when the endpoints shouldn't be included or you want midpoints instead.
The quirks
Integer division truncates. 10/4 in starts gives [0, 2, 5, 7], not [0, 2.5, 5, 7.5] - it's integer arithmetic throughout, so "evenly spaced" is only approximate when the total doesn't divide cleanly. For most sampling that's fine; for precision you'd want float output, and this isn't the node for it.
denominator of 1. In start + end mode, dividing by denominator - 1 means a denominator of 1 causes a division by zero - Python will raise. The other modes with denominator 1 produce a single-element list. Set it to at least 2 for start + end.
Unknown type raises. The four strings are the whole menu; anything else errors with a descriptive message. There's no validation of numerator/denominator ranges otherwise, so keep them positive and sane.
Install
ComfyUI Manager (search "Nilor Nodes") or:
cd ComfyUI/custom_nodes
git clone https://github.com/nilor-corp/nilor-nodes
cd nilor-nodes && pip install -r requirements.txt
Restart ComfyUI; it's under Nilor Nodes ๐บ โ Utilities. No dependencies.
Bottom line
A tiny but surprisingly central utility: "give me N evenly spaced index points across a range" in four flavors, delivered as a proper list. Learn the four modes once and you'll stop hand-computing keyframe indexes forever. Just remember the integer truncation and the denominator of 1 in start + end mode, and it'll behave.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| numerator | INT | 10 | โ |
| denominator | INT | 2 | โ |
| type | COMBO | 4 options: starts, ends, centres, start + end |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| fractions | INT | โ |