How to code an algorithm to generate a random but valid train track layout?

I am wondering if I have quantity C of curved tracks and quantity S of straight tracks, how I could write a computer program to design a “random” layout using all of those tracks, such that the following rules are satisfied:

1) The tracks, when all connected, form a closed (continuous) loop for the train to go around.

2) Ramps, bending of tracks, bumping of tracks, crossing of tracks are all not allowed.

So would the computer program have to create a geometric model and remember the exact positions of each track or is there some simpler way to code this? I want to be able to “push a button” and the computer “spits out” a valid “new” layout for me.

Do I need to give the exact measurements of the 2 types of tracks? If so, I can provide those.

I have some coding skills but I need to know an algorithm first before I can code something meaningful (other than just testing a few parts of a candidate algorithm)