code: def rand(n, d=None, r=2, samplefunc=_np.random.randn):
      
      n0 = _np.asanyarray(n, dtype=_np.int32)
      r0 = _np.asanyarray(r, dtype=_np.int32)
      if d is None:
          d = n.size
      if n0.size is 1:
          n0 = _np.ones((d,), dtype=_np.int32) * n0
      if r0.size is 1:
          r0 = _np.ones((d + 1,), dtype=_np.int32) * r0
          r0[0] = 1
          r0[d] = 1
      c = _vector.vector()
      c.d = d
      c.n = n0
      c.r = r0
      c.get_ps()
      c.core = samplefunc(c.ps[d] - 1)
      return c
docs: Generate a random d-dimensional TT-vector with ranks ``r``.
      Distribution to sample cores is provided by the samplefunc.
      Default is to sample from normal distribution.