I created a sample code:
<%
Dim randoms As String
Dim I As Integer
%>
<html>
<body>
<% For I = 1 To 6%>
<%randoms &= Hex$(Int(Rnd(65536)), 4)%>
<%Next%>
<h1>Gambas web application</h1>
<table border="1" cellpadding="4" cellspacing="0">
<tr>
<th><%=randoms%></th>
<th>Value</th>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
<%randoms = Null%>
</body>
</html>
Run with the embedded HTTP server.
each page refresh it gives me the same value, why?
Does anyone know why?
I tried also with =. It does not work. Always returns the same value. It seems as if RND did not work in this case
However, if you run a script gbw3, then this works. If I run through apache2, nginx, lighttpd, then also works.
Only in the embedded HTTP server does not work
I can also refer to this function
Public Function getrandom() As String
Dim uniqueid As String
Dim I As Integer
For I = 1 To 6
uniqueid &= Hex$(Int(Rnd(65536)), 4)
Next
Return uniqueid
uniqueid = Null
End
However, any reference to this function returns the same value, only when running is using the embedded HTTP server
I sent a report on this page http://gambaswiki.org/bugtracker/main
But they did not accept my report and have it removed. :bad: :mad:
Public Function getrandom() As String
Dim uniqueid As String
Dim I As Integer
Shell "cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1" Wait To uniqueid
' For I = 1 To 6
' uniqueid &= Hex$(Int(Rnd(65536)), 4)
' Next
Return uniqueid
End
I tried to use here such code, and it works. Returns me every time the page is loaded another string.
Can also do it in that way:
Public Function getrandom() As String
Dim uniqueid As String
Exec ["openssl", "rand", "-hex", "32"] To uniqueid
Return uniqueid
End
Use Randomize keyword before extracting random numbers.
In this way you are sure that each time random number are different.
Like this:
Randomize
For i = 1 To 6
random = Int(Rnd(65536), 4)
Next