Good question. Hang on I'll get there.......
If we are talking about the accompaniment bass line, not the tune, we play notes of the harmonizing chord that the song writer has placed in the song. Why? If the melody line (treble clef) and the harmony line (bass clef) share like notes we get harmony, i.e. the two lines sound good with each other. We count on the song writer to place the harmonizing chord where needed and then we play notes of that chord. In doing that we harmonize with the melody and we sound good with what is happening in the song.
So --- we need to know what chords are active at this moment in the song and play some of their notes to the beat (rhythm) of the song. If our ears are good enough we can rely upon them to tell us what chord is active. My ears are tin, so I rely upon fake chord sheet music. Google can call up fake chord sheet music on just about everything you will need. Once you know the active chord play some of it's notes. Yes I know ---- which ones is the question.
Roots work. After you have found the root a R-5 usually works. Root on the 1st beat and 5 on the 3rd beat. Where is the 5 from the root? Up a string and over two frets, or down a string same fret. Yep, that is where 5ths live. After that I normally bring in a octave 8. Where is the 8 from the root? Up two strings and over two frets, right over the 5. So R-5-8-5 is a generic pattern that will keep you in the game. Roots alone work for Praise music, Roots and fives work for Country and that R-5-8-5 kinda fits with the other stuff.
Go to the General Instruction section and look for post # 14 in the getting started sticky.
How to get started? It will give you the rest of the story.
Yes there is a structure to follow. Random notes usually result in noise.
Good luck