Autore Topic: Gambas Rnd (Web programming)  (Letto 944 volte)

Offline eloaders

  • Gamberetto
  • *
  • Post: 38
    • Mostra profilo
Gambas Rnd (Web programming)
« il: 30 Dicembre 2016, 22:38:51 »
I created a sample code:

Codice: [Seleziona]
<%
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?

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.723
  • Ne mors quidem nos iunget
    • Mostra profilo
Re:Gambas Rnd (Web programming)
« Risposta #1 il: 31 Dicembre 2016, 00:21:23 »
Hello eloaders,

I have also involved the Spanish forum in your question:

https://foro.gambas-es.org/viewtopic.php?f=1&t=6095


Well, an its member asks why do you use &= instead of = ?
He says: maybe is this the problem ?
« Ultima modifica: 06 Giugno 2022, 01:41:46 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline eloaders

  • Gamberetto
  • *
  • Post: 38
    • Mostra profilo
Re:Gambas Rnd (Web programming)
« Risposta #2 il: 31 Dicembre 2016, 02:02:15 »
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
Codice: [Seleziona]
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
« Ultima modifica: 31 Dicembre 2016, 02:10:14 da eloaders »

Offline eloaders

  • Gamberetto
  • *
  • Post: 38
    • Mostra profilo
Re:Gambas Rnd (Web programming)
« Risposta #3 il: 31 Dicembre 2016, 11:32:00 »
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:

Codice: [Seleziona]
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:
Codice: [Seleziona]
Public Function getrandom() As String
  Dim uniqueid As String
  Exec ["openssl", "rand", "-hex", "32"] To uniqueid
  Return uniqueid
End
« Ultima modifica: 31 Dicembre 2016, 12:06:18 da eloaders »

Offline Gianluigi

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 4.244
  • Tonno verde
    • Mostra profilo
Re:Gambas Rnd (Web programming)
« Risposta #4 il: 31 Dicembre 2016, 14:11:34 »
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:


You must subscribe the mailing list for Gambas users

However, the notification has been accepted  :)
 :ciao:
« Ultima modifica: 31 Dicembre 2016, 15:32:53 da Gianluigi »
nuoto in attesa del bacio di una principessa che mi trasformi in un gambero azzurro

Offline Top Fuel

  • Gran Maestro dei Gamberi
  • *****
  • Post: 959
    • Mostra profilo
Re:Gambas Rnd (Web programming)
« Risposta #5 il: 31 Dicembre 2016, 22:19:16 »
Use Randomize keyword before extracting random numbers.
In this way you are sure that each time random number are different.
Like this:

Codice: [Seleziona]
Randomize
For i = 1 To 6
   random = Int(Rnd(65536), 4)
Next
« Ultima modifica: 31 Dicembre 2016, 23:39:57 da Top Fuel »
Dear youtube administrators, your search bar is broken. When I type the letter "J" it appears justin bieber when it should appear Jimi Hendrix. Fix this, please.

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.723
  • Ne mors quidem nos iunget
    • Mostra profilo
Re:Gambas Rnd (Web programming)
« Risposta #6 il: 31 Dicembre 2016, 23:02:46 »
Use the Randomize keyword ...

eloaders,
also jguardon, like Top Fuel, suggests you to use Randomize:

https://foro.gambas-es.org/viewtopic.php?f=1&p=36503&sid=9c2486e4904ac556bef62f8a8e2d3b68#p36503
« Ultima modifica: 06 Giugno 2022, 01:42:08 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline Top Fuel

  • Gran Maestro dei Gamberi
  • *****
  • Post: 959
    • Mostra profilo
Re:Gambas Rnd (Web programming)
« Risposta #7 il: 31 Dicembre 2016, 23:44:09 »
And Rand() function return integer number without using Int() function.
Dear youtube administrators, your search bar is broken. When I type the letter "J" it appears justin bieber when it should appear Jimi Hendrix. Fix this, please.