No. There is no connection between the lottery and your visa except if you win. You do not win the green card, you win the application. Not sure why you thinking that the lottery is not free, but it has been free forever (except for the scam sites).
Military service only gives you green card and residency if it is war time. During non war time, it allows you to apply for citizenship after you served (instead of waiting 5 years), but you need a greencard before that.
With only two exceptions (Philippines and American Samoa), you need to be a permanent resident (i.e, already have a green card) to enlist in the U.S. military if you aren't a citizen.
Military service only gives you green card and residency if it is war time. During non war time, it allows you to apply for citizenship after you served (instead of waiting 5 years), but you need a greencard before that.