It seems like being in the very front line of a roman cohort or similar military unit would practically be a death sentence, as you would be the first up in battle to fight the enemy army.
Were lots picked to determine who would fight at the front? Or were orders just given out? How exactly was this determined?
Presumably you mean the guys who stand in the very front rank of the battle line, and hence at the first men to clash with the enemy. In which case the Hastati, Principe, Triarii comment doesn't really cleave to what you're asking.
So to begin with, your premise about it being a death sentence to be the first man in line is a little bit mistaken. Yes, obviously being in the front rank had its added risks. However, on the offense the Romans would be launch their throwing spears, the deadly pilum just short of contact with the enemy. This served not only to kill the enemy, but disrupt their formation by lodging the spears inside of shields and generally causing chaos as defenders shuffle forward to fill the ranks of dead men, or cast away their maimed shields to pick up replacements. This meant that the enemy was less cohesive then perhaps they would normally be, and the initial shock of combat is less risky for the attacking Roman than it is for (say) an attacking Gaul.
Furthermore, the Roman soldier himself is very well equipped for his time, armored with a good quality helmet and mail cuirass, to say nothing of a shield that offers more or less full body coverage. While dependent on era and opponent, the Romans were typically much better protected than their opponents. This leads to generally lower casualties, and a more durable soldier overall.
Secondly, it doesn't seem that the Romans themselves viewed the idea of 'standing in front' a death sentence. This is evidenced by coveted rewards such as the Corona Muralis being awarded for being the first soldier over an enemy's walls during a siege or assault - a position which probably -is- a death sentence, much more so than standing in the front rank of the Roman battle-line. You could also point to the behavior of Roman Centurions, who bore higher than usual casualty rates, especially during setbacks like Gergovia, where Caesar's centurion corps suffered grievously while leading from the front.
As to how a man's position in battle was actually chosen, this I am less certain of, although I've never heard of lots being drawn or anything like that. I am confident, however, that individual men wouldn't have drawn lots, and who stands in front would've been decided on a Centuria level. Admittedly this next part ventures into speculation, but I imagine that each Centurion would decide within his cohort which Centuria would be at the front for that day...but whether he just chose based on who he felt like 'honoring' that day, or whether the commander of the cohort would place his own century at the head for most occasions, I'm not sure.
One last point is that people may assume that the person on the front line stays there until either he dies or the battle is won, but in practice this was not the case and the Romans had a relief system where they would rotate individual Centuria and even entire Cohorts out of the battle-line and replace them with fresh soldiers.
So in reality, while being in the front line does provide an element of added hazard, it was far from a death sentence.
Let me just finish by leaving you a link to this short video that describes how the Roman Army functioned in battle, which I think you'll enjoy. https://www.youtube.com/watch?v=Ndh3b9wC-A0&feature=player_embedded It's remarkably well done for a five-minute video that uses footage from Hollywood - in particular showcasing how Romans would've deployed a legion into battle. The only aspect I'm shaky on is the last part of the video, where it shows footage of individual soldiers darting back in intervals. Some sort of system like that may have existed, but I'm not sure it worked exactly as shown in the video.