Re: creating utf-8 random strings

From: Michael Wood <esiotrot(at)gmail(dot)com>
To: "Jean-Yves F(dot) Barbier" <12ukwn(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: creating utf-8 random strings
Date: 2011-12-27 08:54:40
Message-ID: CAP6d-HUpHyi8a=yya-QTG-6UjDnHk3gpS+tHrGe_UT4EDQAvqg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi

On 25 December 2011 17:16, Jean-Yves F. Barbier <12ukwn(at)gmail(dot)com> wrote:
> Hi list,
>
> In order to make tests I must create strings [20-32] & [32-64]
> characters long with accentuated characters.
>
> I use a very old piece of code (not even accurated, but sufficient
> until now), however it don't give me lower-case nor accentuated :
> for b in range(random.randint(48, 64)):
>    chiffre = random.randint(65, 88)
>    myStr += unichr(chiffre)
>
> Does somebody has such code?

How about something like this in Python:

#!/usr/bin/env python
# coding=utf-8

import random

def rand_string(length):
# All the characters you want to use in your strings:
test_chars = u"abcdeABCDE12345áàäéèëÁÀÄÉÈË -,."

s = []
for i in range(length):
s.append(random.choice(test_chars))

return "".join(s)

print rand_string(random.randint(48, 64))

--
Michael Wood <esiotrot(at)gmail(dot)com>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message William Rose 2011-12-27 21:53:16 LC_COLLATE UTF-8 Locales on Windows?
Previous Message Thangalin 2011-12-27 08:11:00 Map table data to XPath expressions