per caso qualcuno ha uno scriptino già pronto per generare casualmente un colore esadecimale (tipo nel formato #RRGGBB)?
per caso qualcuno ha uno scriptino già pronto per generare casualmente un colore esadecimale (tipo nel formato #RRGGBB)?
W la Ferari effetrenavenave!
il computer è un somaro veloce! (neanche tanto ndr)
Trovato.... faster than light
Non l'ho ancora provato ma mi incuriosisce il range di valori da 0 a 256...codice:Protected Function HexColGenerator() As String Dim RandomClass As New Random() Dim intR, intG, intB As Integer intR = RandomClass.Next(0, 256) intG = RandomClass.Next(0, 256) intB = RandomClass.Next(0, 256) Dim hexR, hexG, hexB As String hexR = intR.ToString("X").PadLeft(2, "0"c) hexG = intG.ToString("X").PadLeft(2, "0"c) hexB = intB.ToString("X").PadLeft(2, "0"c) Dim strColor As String = "" strColor = "#" & hexR & hexG & hexB Return strColor End Function
W la Ferari effetrenavenave!
il computer è un somaro veloce! (neanche tanto ndr)
Come non detto, trovata anche luce sul range di valori:
The Next(Int32, Int32) overload returns random integers that range from minValue to maxValue – 1.
W la Ferari effetrenavenave!
il computer è un somaro veloce! (neanche tanto ndr)
ma non è 255 ?
press play on tape
-----
MP3 Listing
https://sourceforge.net/projects/mp3-listing
File Listing
https://sourceforge.net/projects/file-listing-2-0/
Pagina:
codice:<form id="form1" runat="server"> <div> <asp:Label ID="lb" runat="server">__________</asp:Label> </div> </form> -- protected void Page_Load(object sender, EventArgs e) { System.Drawing.Color x = ColoreRandom.RandomColor(); lb.BackColor = x; }
Classe C#:
codice:class ColoreRandom { public static Color RandomColor() { Random rnd = new Random(); return Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)); } }
se fai F5 sulla pagina vedrai un colore diverso ad ogni caricamento. Traducila in VB..
press play on tape
-----
MP3 Listing
https://sourceforge.net/projects/mp3-listing
File Listing
https://sourceforge.net/projects/file-listing-2-0/
Grazie capo!
Però il tuo code ha un buco perchè, come ho postato sopra in verde, l'istruzione rnd.next ti riduce il limite massimo a 255-1.... col tuo codice non vedrai mai un bianco, un verde, un rosso o un blu puri perchè si fermerà a 254
W la Ferari effetrenavenave!
il computer è un somaro veloce! (neanche tanto ndr)
(mi immagino il moderatore incredulo che prova 2500 volte a vedere se gli esce un colore puro col 255 eh eh eh)
io mica lo sapevo, me l'ha detto Bill Gates, vedi qui nelle note https://msdn.microsoft.com/it-it/lib...v=vs.110).aspx
W la Ferari effetrenavenave!
il computer è un somaro veloce! (neanche tanto ndr)
Non mi importava piu' di tanto perche' dovevo solo dare un colore ad ogni utente connesso, non avevo bisogno di un range completo ad ogni costo.
Comuque non ho capito cosa significa
Come non detto, trovata anche luce sul range di valori:
The Next(Int32, Int32) overload returns random integers that range from minValue to maxValue – 1.
modificando la riga che genera il colore in
return Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
funziona lo stesso, comunque![]()
credevo che il tuo commento si riferisse ad un limite...
Ultima modifica di djciko; 08-11-2016 a 18:10
press play on tape
-----
MP3 Listing
https://sourceforge.net/projects/mp3-listing
File Listing
https://sourceforge.net/projects/file-listing-2-0/
press play on tape
-----
MP3 Listing
https://sourceforge.net/projects/mp3-listing
File Listing
https://sourceforge.net/projects/file-listing-2-0/