Here is a handy LM317 constant current calculator/tool. It allows you to quickly calculate the set resistor and the heatsink (is needed).
Sections of the calculator
Ambient temperature – this is the temperature of the surrounding air / environment. You can increase this variable accordingly.
Thermal Resistance, Junction-to-case, θJC – taken from LM317 datasheet. Different packages have different value.
Thermal Resistance, Junction-to-ambient, θJA – again, see this value in the datasheet
Thermal Resistance, Case-to-heatsink(no thermal compound), θCH – this one is an conservative estimate. It’s better to calculate worst case scenario then optimistic scenario. It will be lower in real world if you use thermal paste.
VIN – the input voltage. To minimize the heat it’s recommended to use as low value as possible. Bare in mine that you still need about 2.5V across LM317.
ISET – this one is clear. Input your desired current value.
RLOAD – input the load resistance. This one will give you the VF value which is the resulting voltage across the regulator. If resulting value is lower than 2.5V VF is displayed in red. This means that the regulator will not work.
θHS – this is the thermal resistance of the heatsink. You should be able to get this value from its datasheet. The better the heatsink the lower the value.
R1 = ISET x 1.25V – calculated value in Ohms
VOUT = ISET x RLOAD – calculated value in volts
PIC1 = (VIN – VOUT) x ISET – calculated value in watts
PR1 = ISET^2 x R1 – calculated value in watts
tºIC1 = tºAMB + PIC1 x θJA – calculated value in ºC
tºIC1HS = tºAMB + PIC1 x (θJC + θCH + θHS) – calculated value in ºC
LM317 spreadsheet >>>LINK<<<