Usually 2 per level, rolled from a list of candidates without repeats. The exception is the Master librarian, which rolls 3 but only has 2 candidates (the two candles) and offers both. A villager needs 0, 10, 70, 150 and 250 total XP to reach levels 1 to 5, and it earns XP every time you use a trade.