Translate code to OB

Hi, i have this part of code in java i think, its a code that allows you to generate the login request :

int tokenEg = ((int)(Math.floor((Math.random() * username.length()))));

{"email":"*******","password":"*******","noCrossAuth":false,"eg":1,"ri":2,"fk":"fe"}

int tokenEg
declare variable tokenEg as integer
Math.floor()
Returns the value less than or equal to the specified number
ex 4.78 = 4.00
Math.random()
generate random number
username.length()
length of the username

I know what each part means but i don’t know how can i proceed to apply that in the OB program.
I noticed there are options to add floor, random integer and length of username but how can i combine? and multiply like the code does, ty.

If you’re using OB2 you can use C# which is pretty similar to java.

int tokenEg = ((int)(Math.Floor((data.Random.Next() * input.USERNAME.Length))));

You can do the same with blocks easily. You want to start from the Length, then the random, then use a COMPUTE block to multiply them together, then pass the result to a Floor block and you’re done.

1 Like

I got this error when i try to compute variables

EvaluateException
[Executing block Compute] Cannot find column [lengthOutput].

Does that mean he cannot convert or understand variable, do i need to do something more?

Please post the code otherwise I cannot know what you did

BLOCK:Length
  input = "input.USERNAME"
  => CAP @lengthOutput
ENDBLOCK

BLOCK:RandomInteger
  => CAP @randomIntegerOutput
ENDBLOCK

BLOCK:Compute
  input = @lengthOutput*@randomIntegerOutput
  => CAP @computeOutput
ENDBLOCK

I tried to do with the blocks as you told me, but i think i’m doing something wrong, do i need to convert the variable first or?

BLOCK:Length
  input = @input.USERNAME
  => CAP @lengthOutput
ENDBLOCK

BLOCK:RandomInteger
  => CAP @randomIntegerOutput
ENDBLOCK

BLOCK:Compute
  input = $"<lengthOutput>*<randomIntegerOutput>"
  => CAP @computeOutput
ENDBLOCK
1 Like

Ok i’m dumb i didn’t specify the input, thanks