We cannot know the reason why the range
function outputs duplicate content, without seeing the source of the project or if you cannot share it, then please provide a sample repository that replicates the issue.
ref: forum Requesting Help guidelines