Line source on generator cc

I have a detector to get the gamma spectrum from a Cs-137 (662 KeV) point source. But, now I have to change my point source into a line source (at least 2 cm long line source)?

Here is my generator.cc code:

Is this correct? will it simulate 20 Cs-137 ions with 2 mm separation or have I made any mistakes?

#include "generator.hh"
#include "G4SystemOfUnits.hh"
#include "Randomize.hh"

MyPrimaryGenerator::MyPrimaryGenerator()
{
    fParticleGun = new G4ParticleGun(1);

}

MyPrimaryGenerator::~MyPrimaryGenerator()
{
    delete fParticleGun;
}


void MyPrimaryGenerator::GeneratePrimaries(G4Event *anEvent)
{


    G4int Z = 55;
    G4int A = 137;    

        G4double charge   = 0.*eplus;
        G4double energy = 0.662*MeV;

    G4ParticleDefinition* particle;
    G4ParticleDefinition* ion = G4IonTable::GetIonTable()->GetIon(Z,A,energy);
    G4double x0 = 0.0*mm;
    G4double x1 = 2.0*mm;
    G4double x = x0 + (x1-x0)*G4UniformRand()*20;
    
        G4ThreeVector pos(0., 0., x);
        G4ThreeVector mom(0., 0., 1.);


        fParticleGun->SetParticlePosition(pos);
        fParticleGun->SetParticleDefinition(ion);
        fParticleGun->SetParticleCharge(charge);


    fParticleGun->GeneratePrimaryVertex(anEvent);

}