I'd like to create line with random thickness using GLSL. But I don't know how to begin (I've started learning GLSL only yestarday).
Could someone please give some code example.
If you have only just started shaders check out some "Hello World" shader examples first. Wide lines aren't very hard until you want to do polylines. There are plenty of examples if you google "opengl wide lines"
There is no way to control the line thickness from inside a shader. glLineWidth() lets you set a uniform thickness for all line segments, though.
The only way to achieve varying line thinkness among the various line segments in a single draw call would be to use a geometry shader: turn the line primitives into screen-aligned quads (along the original line) inside the geometry shader. The elongated quads will then look line wide lines and each 'line segment' can have its own thinkness.