Randomized greedy algorithms for independent sets and matchings in regular graphs: Exact results and finite girth corrections