(Bash): Umyalo wokukhiqiza inombolo engahleliwe

Kwesinye isikhathi, sihlela iskripthi esithile ku- Bash …. futhi sidinga (ngasizathu simbe) ukukhiqiza inombolo ethile engahleliwe.

Ngalokho ungalungiselela uhlelo lonke (noma usebenze ...) yebo, kepha ... ngokumangazayo uhlelo lwethu selukwenzile lokho 😀

Ku-terminal, thayipha okulandelayo bese ucindezela [Faka]:

kunanela $ RANDOM

... kuzovela inombolo, baphinde benze into efanayo bese kuvela enye inombolo, njalonjalo 🙂

Lokho ekwenzayo ukukukhombisa inombolo engahleliwe (noma yikuphi) phakathi kuka-0 no-32768 (inani eliphelele, okungukuthi, ngaphandle kwekhefana).

Uma uyidinga ukuthi ibe yinombolo engahleliwe, kepha phakathi kuka-0 no-ake sithi 100, ungabeka lowo mkhawulo kuyo 😀

i-echo $ (($ RANDOM% 100))

Okufanayo, esinye isibonelo ... uma ufuna ukuthi kube inombolo ephakathi kuka-0 no-29 kungaba:

i-echo $ (($ RANDOM% 29))

Ngabe akuqondakali? 😀

Uma bezoyisebenzisa kumbhalo we-bash abawenzayo, ukwabela inani elakhiwe (inombolo engahleliwe) kokuguquguqukayo kungaba:

VARIABLE = `echo $ (($ RANDOM))`

Futhi konke lokhu kuphela, angazi ngawe ... kepha ngiyazi ukuthi kuzoba wusizo kimi kwesinye isikhathi hahaha.

Phendula ngokucaphuna


Okuqukethwe yi-athikili kunamathela ezimisweni zethu ze izimiso zokuhlelela. Ukubika iphutha chofoza lapha.

Amazwana ayi-9, shiya okwakho

Shiya umbono wakho

Ikheli lakho le ngeke ishicilelwe. Ezidingekayo ibhalwe nge *

*

*

  1. Ubhekele imininingwane: Miguel Ángel Gatón
  2. Inhloso yedatha: Lawula Ugaxekile, ukuphathwa kwamazwana.
  3. Ukusemthethweni: Imvume yakho
  4. Ukuxhumana kwemininingwane: Imininingwane ngeke idluliselwe kubantu besithathu ngaphandle kwesibopho esisemthethweni.
  5. Isitoreji sedatha: Idatabase ebanjwe yi-Occentus Networks (EU)
  6. Amalungelo: Nganoma yisiphi isikhathi ungakhawulela, uthole futhi ususe imininingwane yakho.

  1.   oscar kusho

    Yebo, bengikade ngiyivivinya futhi ibuyisa kuphela inombolo enamadijithi ama-4, ngingayenza ibe nkulu kanjani?
    Ithiphu ethakazelisa kakhulu, ngiyabonga.

    1.    KZKG ^ Gaara kusho

      Ibuyisa inombolo phakathi kuka-0 no-32768, angikwazi ukuthola izinombolo ezinkulu.

  2.   josue kusho

    futhi ingakhiqiza ama-exadecimals ????

  3.   I-raven kusho

    VARIABLE = `echo $ (($ RANDOM))`

    Lokho kuyasebenza kepha akulungile, ngesizathu esilula sokuthi i-RANDOM iyehluka futhi ungakwenza:
    okuguqukayo = $ RANDOM
    futhi yilokho kuphela! ungasebenzisi i-echo ku-aprte yesiginali (okuyilokho okwenzayo)

    1.    KZKG ^ Gaara kusho

      Yebo, kusobala ukuthi ingafinyelelwa kanjena ... umehluko kuphela ukuthi ngokuhamba kwesikhathi, ukubona inombolo okuthathwe ukuguquguquka (ngoba umsebenzisi akayena umqageli), kungadingeka ukwenza i-echo .... futhi ekugcineni, engikwenzayo lapha ukumane wenze i-echo (ukuze umsebenzisi abone ukuthi iyiphi inombolo ethathiwe) kwasekuqaleni.

      Ingabe ngenza ukuba ngiqondwe? 🙂

  4.   I-Wuilmer bolivar kusho

    Enye indlela yokwenza inombolo engahleliwe, yize kulokhu kungaba yilo myalo:

    usuku "+% N" | sika -c 9

    Lokho kungasinika usuku kuma-nanoseconds anezinombolo eziyi-9. Uma sifuna idijithi eyodwa, khona-ke ubeka u- "cut -c 9" (idijithi yokugcina ihlale ingahleliwe ngoba yinombolo encane kunazo zonke). Uma sifuna izinombolo ezi-2 bese sibeka u- "cut - c 8,9". Uma sifuna izibalo ezintathu bese "cut -c 7-9" (siqala ukusebenzisa ikhonco).

    Okuwukuphela kwento embi ngalokhu ukuthi uma sifuna ukuthola izinombolo eziningi ezingahleliwe zilandelana ngesikhathi esifushane, ngoba le yinombolo engahleliwe ngokususelwa kudethi nesikhathi sayo. Lokho wukuthi, uma senza i- for ngalo myalo singabona ukuthi:

    $ for i ku `seq 1 1 500`; idethi "+% N"; kwenziwe

    ...
    ...
    ...

    308311367
    310807595
    313273093
    315725181
    318186139
    320671403
    323360117
    325733353
    328335462
    330694870
    333259893
    335858999
    338375622
    340798446

    ...
    ...
    ...

    Ngicabanga ukuthi kucacile angithi? Izibalo ezingakwesobunxele ziyefana kakhulu ngesikhathi esifushane, kunjalo, futhi lezo ezingakwesokudla "zingahleliwe".

  5.   iso elimnyama kusho

    mmm…. Ngiwuthandile, ngineskripthi esincane, sipendiwe ukukhiqiza izinombolo ezingahleliwe, ngiyabonga.

  6.   G. kusho

    Kuyakhonza .. nokuningi ..
    ikakhulukazi uma uhlela isikhombimsebenzisi ku-bash nephasiwedi, ukuphepha, njll, njll, njll haha.
    I-aprote enhle kakhulu.

  7.   UJosé Antonio Ulandele iBent kusho

    Sawubona!
    Okokuqala, ngihalalisela ngale webhusayithi enhle kakhulu, engikade ngiyilandela isikhathi eside.
    Futhi okwesibili, bhala okuncane kulokhu okufakiwe:
    Lapho ukukhawulelwa kwenziwa kanjena:

    i-echo $ (($ RANDOM% 10))

    Empeleni, oku-oda utolika ukuthi inombolo yakho ekhiqizwayo i-modulus% (okusele kokuhlukaniswa) kwenombolo elandelayo, kulesi sibonelo, 10.
    Noma iyiphi inombolo ehlukaniswe ngo-10 ayisoze yanikela njengensalela okuthile okukhulu kunokwahlukanisi uqobo.
    Inkinga ukuthi nayo ngeke inikeze inombolo efanayo, ngoba ukwahlukaniswa ngo-0 akunangqondo kutolika.

    Lokhu kusho ukuthi i-echo $ (($ RANDOM% 10) izonikeza imiphumela phakathi kuka-0 no-9, kepha hhayi i-10.
    Isixazululo sale ngxabano ukufaka eyodwa kumkhawulo wakho, ukuze inombolo efanayo iwele ebangeni elingahleliwe.

    i-echo $ (($ RANDOM% 11))

    Lokhu kuzonikeza imiphumela phakathi kuka-0 no-10.

    A ukubingelela.