Generate 10digits random number without repeating number

 

Guys happy coding and Trading.

I would like to ask your ideas and knowledge on how to get the above SUBJECT.

I have that module when I doing my visual studio project. But here in mql5 I don't know how.

I try to google for 2days but nothing happen.

The scenario:

my EA are completely finish and functional. I would like to put a password.

I would like to GENERATE a 10digit PASSWORD without repeating numbers.

i using Mathrand() but not meet the needs.

      int xxx= int((9 * MathRand()) + 1);

 Question:

Is there a possibility to meet my needs by using MQL5 codes?

if possible can I ask here your guides on how to code that?

-Thank you for your reading ang time to my concern.

 
Michael Quinatadcan Macasil Macasil: I would like to GENERATE a 10digit PASSWORD without repeating numbers.
I'm not sure what you mean by "without repeating numbers". If you mean always generating a unique password every time, then you could try also including the date and time to make it more unique and then just encrypt it.
Documentation on MQL5: Common Functions / CryptEncode
Documentation on MQL5: Common Functions / CryptEncode
  • www.mql5.com
CryptEncode - Common Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Michael Quinatadcan Macasil Macasil: i using Mathrand() but not meet the needs.
int xxx= int((9 * MathRand()) + 1);

By the way, your function does not create a 10 digit code. It generates a value between 1 and 294904, which is at most 6 digits (1 digit in the least).

Documentation on MQL5: Math Functions / MathRand
Documentation on MQL5: Math Functions / MathRand
  • www.mql5.com
MathRand - Math Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro:
I'm not sure what you mean by "without repeating numbers". If you mean always generating a unique password every time, then you could try also including the date and time to make it more unique and then just encrypt it.

I'm not sure what you mean by "without repeating numbers".

I have

0123456789

and plan to scramble these number.

"thanks for early response".

 
Michael Quinatadcan Macasil Macasil: I have 0123456789 and plan to scramble these number.

Then do exactly that, jumble up the sequence of the characters in that string "0123456789".

How are you doing it in your Visual Studio project?

You did not mention in what language, but whatever the language I will assume you are just manipulating a string and jumbling up the sequence of the characters in a random way.

Just replicate that in MQL using the MQL string manipulation functions.

 
Fernando Carreiro:

Then do exactly that, jumble up the sequence of the characters in that string "0123456789".

How are you doing it in your Visual Studio project?

You did not mention in what language, but whatever the language I will assume you are just manipulating a string and jumbling up the sequence of the characters in a random way.

Just replicate that in MQL using the MQL string manipulation functions.

attached are vs.

ok I try to explore 

manipulating a string with MQL5 codes. 

But if you guys have an idea of what I needs please post your code. thanks in advance

Files:
xxx.jpg  192 kb
 
Michael Quinatadcan Macasil Macasil: attached are vs. ok I try to explore  manipulating a string with MQL5 codes. But if you guys have an idea of what I needs please post your code. thanks in advance

You can basically do it in the same way as your Visual basic code. Just remember that the functions in MQL work differently so check the documentation.

For example MathRand() returns an integer between 0 and 32767 and not a double between 0.0 and 1.0, so adjust the code accordingly.

 
Michael Quinatadcan Macasil Macasil:

Guys happy coding and Trading.

I would like to ask your ideas and knowledge on how to get the above SUBJECT.

I have that module when I doing my visual studio project. But here in mql5 I don't know how.

I try to google for 2days but nothing happen.

The scenario:

my EA are completely finish and functional. I would like to put a password.

I would like to GENERATE a 10digit PASSWORD without repeating numbers.

i using Mathrand() but not meet the needs.

 Question:

Is there a possibility to meet my needs by using MQL5 codes?

if possible can I ask here your guides on how to code that?

-Thank you for your reading ang time to my concern.

Why your passwords need to be that way?  You know that they will be lame, right?

 
a simple "not optimized" code might look like this:
void getRandom(int &val[10]) 
{
   bool used[10];
   for(int i = 0; i < 10; i++)
      used[i] = false;      
   for(int i = 0; i < 10; i++)
   {
      MathSrand(GetTickCount());
      while (true)
      {
         int x = (int)MathRand() % 10;
         if (used[x] == false)
         {
            used[x] = true;
            val[i] = x;
            break;
         }
      }
   }
}

void OnStart()
  {
      int val[10];
      getRandom(val);
      
      string password = "";
      for(int i = 0; i < 10; i++)
         password += IntegerToString(val[i]);
         
      Print(password);
  }
//+------------------------------------------------------------------+
good luck.
 
Soewono Effendi:
a simple "not optimized" code might look like this:
good luck.

I am very thankful for sharing your codes. two thumbs up for your kindness.

 
Fernando Carreiro:

Then do exactly that, jumble up the sequence of the characters in that string "0123456789".

How are you doing it in your Visual Studio project?

You did not mention in what language, but whatever the language I will assume you are just manipulating a string and jumbling up the sequence of the characters in a random way.

Just replicate that in MQL using the MQL string manipulation functions.

thanks foe these "just manipulating a string and jumbling up". My EA are now completely finished.

PROBLEM SOLVED.

//+------------------------------------------------------------------+
//|      Password Generator / code gate                              |
//+------------------------------------------------------------------+
void pwG()//Code Gate
  {
   int x = (int)MathRand() % 10;
   if((x==0)&&(a==9))
     {
      a=x;
      if(StringLen(nPW)<=10)
        {StringAdd(nPW, IntegerToString(0));}
     } 

see attached.

Files:
cGate.jpg  189 kb
screenlock.jpg  180 kb
Reason: