0

How to use code to edit out unique non-repeating random numbers?

How to use code to edit out unique non-repeating random numbers? Thank you for your reply.

 

6 replies

null
    • Fred
    • 2 mths ago
    • Reported - view

    Can you provide a sample of the data?

      • gold_cat
      • 2 mths ago
      • Reported - view

       

      function randomId() do
          let chars := "1234567890ABCDEFGHJKLMNPQRSTUVWXYZ";
          let len := length(chars);
          join(for i from 0 to 8 do
              substr(chars, floor(random() * len), 1)
          end, "")
      end;
      let done := false;
      while not done do
          let i := randomId();
          if count(select 'Orders' where 'Random letters and numbers' = i) = 0 then
              'Order Number' := "H" + randomId() + "B";
              done := true
          end
      end

          if count(select 'Orders' where 'Random letters and numbers' = i) = 0 then

      thanks,The condition statement is like this, but if there are duplicates, how to generate a non-duplicate number again, how to write this.

      • Fred
      • 2 mths ago
      • Reported - view

      I'm not sure what you want to do. You ask to "edit out unique non-repeating random numbers". Then you give a string that has numbers and letters. Can you describe in more detail what you want to have happen?

      • gold_cat
      • 2 mths ago
      • Reported - view

       

      The random numbers I generate with this piece of code have a probability of repeating, so how can I solve this problem?

    • Alain_Fontaine
    • 2 mths ago
    • Reported - view
    let done := false;
    let i := randomId();
    while not done do
        if count(select 'Orders' where 'Random letters and numbers' = i) = 0 then
            'Order Number' := "H" + i + "B";
            done := true
        else
            i := randomId()
        end
    end
    
      • gold_cat
      • 2 mths ago
      • Reported - view

       Thank you. I'll try the way you said.

Content aside

  • 2 mths agoLast active
  • 6Replies
  • 61Views
  • 3 Following