A power supply for controlling current and arranged to perform power factor correction, the power supply comprising: a rectifier arranged to rectify a first current (I SW); a transformer arranged to receive said first current (I SW) at its first side, and to convert said first current (I SW) into a second current at its second side and to supply the second current (I OUT) to a load line unit; and a sampler arranged to sample a peak value of the first current (I SW); characterised in that the power supply further comprises: an integrator (412, 712) arranged to use a signal proportional to the peak value (I PK) of the first current (I SW) and to output a voltage signal (V fb) proportional to an average value of a current flowing through the load line unit; a switching controller connected to said integrator (412, 712) and arranged to receive therefrom the output voltage signal (V fb), the switching controller arranged to control a time during which the first current (I SW) at the first side of the transformer flows by means of the output voltage signal (V fb) of the integrator (412, 712); and a level detector arranged to receive an input sinusoidal form from the rectifier, to transfer a reset signal (V reset) to the integrator and to determine an integration cycle of the integrator in accordance with a cycle of an input voltage. a rectifier arranged to rectify a first current (I SW); a transformer arranged to receive said first current (I SW) at its first side, and to convert said first current (I SW) into a second current at its second side and to supply the second current (I OUT) to a load line unit; and a sampler arranged to sample a peak value of the first current (I SW); characterised in that the power supply further comprises: an integrator (412, 712) arranged to use a signal proportional to the peak value (I PK) of the first current (I SW) and to output a voltage signal (V fb) proportional to an average value of a current flowing through the load line unit; a switching controller connected to said integrator (412, 712) and arranged to receive therefrom the output voltage signal (V fb), the switching controller arranged to control a time during which the first current (I SW) at the first side of the transformer flows by means of the output voltage signal (V fb) of the integrator (412, 712); and a level detector arranged to receive an input sinusoidal form from the rectifier, to transfer a reset signal (V reset) to the integrator and to determine an integration cycle of the integrator in accordance with a cycle of an input voltage. an integrator (412, 712) arranged to use a signal proportional to the peak value (I PK) of the first current (I SW) and to output a voltage signal (V fb) proportional to an average value of a current flowing through the load line unit; a switching controller connected to said integrator (412, 712) and arranged to receive therefrom the output voltage signal (V fb), the switching controller arranged to control a time during which the first current (I SW) at the first side of the transformer flows by means of the output voltage signal (V fb) of the integrator (412, 712); and a level detector arranged to receive an input sinusoidal form from the rectifier, to transfer a reset signal (V reset) to the integrator and to determine an integration cycle of the integrator in accordance with a cycle of an input voltage.