18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

random letter

lepierrotlepierrot Members
edited November -1 in Sahi - Open Source
if I set :
var $alphabet = "abcdefghijklmnopqrstuvwxyz";
var $new_letter = " ";
$new_letter = $alphabet.charAt(Math.round(26 * Math.random()));
It should return me a random letter no ?
Because it doesn't work ... :(
Is there an inclusion I 've missed ?

Comments

  • Hi lepierrot,

    I tried using your code and it works fine when i test it in evaluate window of the sahi controller. Where exactly are you facing the problem?

    Regards,
    Pankaj.
  • Hi Pankaj,

    It's ok I've found the solution. It was in the declaration of my variable... :)
    It works perfectly and I've created a randomly string generating function!

    If anybody 's interested, let me know.
  • Thats great!! :)

    Ya that piece of code will be handy. I also need to generate some names on fly.

    Regards,
    Pankaj.
  • lepierrotlepierrot Members
    edited June 2008
    As promised :
    function random_string($length_str){
        var $alphabet = "abcdefghijklmnopqrstuvwxyz";
        var $rand_str = ""; // string you want to create
        var $number_str = 0; // rank of the current letter 
        var $new_letter ;
        for($l=0;$l<$length_str;$l++){
            $new_letter = $alphabet.charAt(Math.round(26 * Math.random()));
            $rand_str += $new_letter;
            $number_str++;
        }
        return $rand_str; 
    }
    
    with : length_str = length of the random string you want to create

    :)
  • Thanks a ton!! :)

    Regards,
    Pankaj.
Sign In or Register to comment.